- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2014 07:23 PM
I have an OU call consultant that we store consultant ad accounts in. I have also created a Consultant true/false field on the sys_user table. I am trying to mark the consultant field to true when the source field contains OU=Consultant. I have crated this business rule to make the change.
Before
insert/update
var target = new GlideRecord("sys_user");
target.addQuery("consultant","CONTAINS","OU=Consultant");
target.query();
while (target.next()){
target.consultant = "true";
target.update();
}
Am I missing something?
Solved! Go to Solution.
- Labels:
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2014 08:51 AM
I forgot to wrap it in a function.
checkConsultant();
function checkConsultant(){
if(current.u_consultant)
return;
if(!current.u_consultant)
current.u_consultant = true;
}
That error goes away. However I would *really* suggest taking care of this in the LDAP transform map if at all possible.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2014 07:39 PM
Consultant is a custom field I'm guessing, so it should be 'target.u_consultant = true;' You shouldn't need to do a glide record query in the first place though, as the system knows which user record is updating/inserting. If you wanted to keep the business rule, it could look something like this:
When: Before
Insert/Update: True
Condition: current.source.toLowerCase().indexOf('consultant') > -1
if(current.u_consultant)
return;
if(!current.u_consultant)
current.u_consultant = true;
However I would look to populate that via the LDAP import. Just add this script:
var source = source.u_source.toString().toLowerCase();
//can also use indexOf('consultant')
if (source.indexOf('ou=consultant') > -1){
target.u_consultant = TRUE;
}
If you want to avoid adding that as a script to run every time the import insert/updates, you can just set up a new LDAP OU definition and transform map for the Consultants OU.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2014 08:32 AM
Thank you for the response! I used the code you provided for the business rule.
I have this in the condition field: current.source.toLowerCase().indexOf('consultant') > -1
I have this in the script field:
if(current.u_consultant)
return;
if(!current.u_consultant)
current.u_consultant = true;
I am getting this error when saving.
JavaScript parse error at line (2) column (6) problem = invalid return
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2014 08:51 AM
I forgot to wrap it in a function.
checkConsultant();
function checkConsultant(){
if(current.u_consultant)
return;
if(!current.u_consultant)
current.u_consultant = true;
}
That error goes away. However I would *really* suggest taking care of this in the LDAP transform map if at all possible.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2014 09:05 AM
That worked thank you.
I agree that this should be running on the ldap transform map. I was hoping the business rule could address the current records that have already been through the map.