cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Occasional Advisor

Assigning a badge to the user logged in once an "if" condition is met?

Any tips on to how to code the assigning of a badge to the user logged  once an "if" condition is met?  

 

<#if finished>
window.setTimeout(
function(){
$('#imageIncomplete').fadeOut(1500);
}, 4000);
window.setTimeout(
function(){
$('#imageSuccess').fadeIn(1500);
}, 4000)
< -- #I want to assign badge here -->
;
</#if>

 

Community Manager +
Learning Media/Content Producer
6 Replies 6
Highlighted
Occasional Advisor

I got a temp solution by making an Advanced Badge Rule, however what I really want to do  for a custom solution is to write to the database a var condition that is met, and that global variable can be used in an advanced badge rule in cases there is not a predefined rule.

 

I used this to check to see if defaults were changed in profile. 

 

setting.profile.signature != 'default'

Create complex badge rule formulas with the Advanced Editor

http://community.lithium.com/t5/Badges/Create-complex-badge-rule-formulas-with-the-Advanced-Editor/t...

 

About badge rules and supported badge criteria

http://community.lithium.com/t5/Badges/About-badge-rules-and-supported-badge-criteria/ta-p/117227

Community Manager +
Learning Media/Content Producer
Highlighted

The easiest to achieve what I understand you want to achieve (which might be wrong, so please feel free to share some more background about your badging example):

  1. Have your custom component assign a new Lithium user role to the relevant user if your condition is met
  2. Create your badge rule to assign this badge to everyone with the dedicated role from step 1
If you appreciate my efforts, please give me a kudo ↓
Accept as solution to help others find it faster.
Highlighted

Very helpful. This sounds like it will work however, any idea what is the script to add a logged in user to a role? 

Thanks!

Ryan

Community Manager +
Learning Media/Content Producer
Highlighted

ou would use the add role API call, but I'm actually it confused on how to use it since according to the documentation there seems to be a way to pass the user ID (which you can get for the current user from the context object), but I'm unclear about how to pass the role ID.
Here's the Community v1 documentation I was looking at: http://community.lithium.com/t5/Developer-Documentation/bd-p/dev-doc-portal?section=commv1&leaf-id=R...
If you appreciate my efforts, please give me a kudo ↓
Accept as solution to help others find it faster.
Highlighted

Thank you. :]
Community Manager +
Learning Media/Content Producer
Highlighted

I published a couple of bits and bobs that add roles to users for different purposes. Maybe you'll find something helpful in there.

 

http://community.lithium.com/t5/Developers-Discussion/Badge-for-consecutive-daily-logins/m-p/207446

http://community.lithium.com/t5/Developers-Discussion/Code-redemption-aka-user-self-help-role-adding...

 

Long story short, add or remove a role:

<#assign result = restadmin("/roles/name/<role>/users/add?role.user=id/${user.id}")/>
<#assign result = restadmin("/roles/name/<role>/users/remove?role.user=id/${user.id}")/>

 


CM at Spotify
Community Ergo Sum