- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2023 10:03 AM
Hi All,
My requirement is in CMS table Mapping when i am doing field mappings ..so ,writing a script for getting a field value from Impact table to do field mapping with Knowledge table(to populate the 'Opened_by'(userfield) User first group(from the group list of Opened_by User) in Knowledge group field after doing a click on "Create Knowledge Error" button ) .
"Create Knowledge Error" (Button) functionality :
When we click on this button in Impact Form , it will redirect to Create Form of Knowledge article .
Need :
After clicking button , Knowledge article form should have auto-populated values form impact table.
Issue :
In below code ..when i am calling 'opened_by' getUserID() value in encodedQuery() , code is not working ..Could you help me here what i needs to correct here .
[Note:below script writing on 'u_impact' Table]
(function(source))
{
var oc = gs.getUserID('current.parent.opened_by');
var grUser = new GlideRecord('sys_user_grmember');
grUser.addEncodedQuery('active.group=true^user='+source.oc);
grUser.setLimit(1);
grUser.query();
var count = grUser.getRowCount();
grUser.next();
if(count==1)
return grUser.getValue('group');
else{
return '' ;
}
}
)
I suspect there is an error in syntax in line no :5 (when i tried in backgroud script it's not getting value from opened_by field )
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2023 11:40 AM
Hi Emir ,
Thanks for your efforts ...When i am debugging the code just now i found a small mistake in below code
actually it should give like
var oc = current.opened_by;
it should not be like
var oc = gs.getUserID('current.parent.opened_by');
Note:in 2 nd line i should not give current.parent ....it should be current.opened_by
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2023 10:15 AM
Hi Sharadha,
From where are you getting the value of "opened_by"? I guess you are writing a field mapping script, hence current won't work.
gs.getUserID() will return you the sys_id of the current logged user. Source means the value which will be stored in the source table. Is that field a reference or a string field in the source table?
Instead just write -
var oc = gs.getUserID();
var grUser = new GlideRecord('sys_user_grmember');
grUser.addEncodedQuery('active.group=true^user.sys_id='+oc); // this might work
Regards,
Shubham Sanjay Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2023 10:15 AM - edited 02-08-2023 10:17 AM
break line 5 into 2 pieces and get each working on its own. then combine them. So take the active group check out for now, add it back in when part 2 is working.
You have a variable oc, use it in the query user='+source.oc which then becomes user='+oc [source is a field you have in your membership table that you don't seem to need here]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2023 10:18 AM
Hi Sharadha,
In field mapping script you cannot use current to get the value from the source field.
The field where the value is being stored, is it a string field or a reference field?
Try the below script, it might work -
var oc = gs.getUserID(); // will take the sys_id of current logged in user
var grUser = new GlideRecord('sys_user_grmember');
grUser.addEncodedQuery('active.group=true^user_sys_id='+oc);
Regards,
Shubham Sanjay Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2023 10:33 AM
Hi Emir ,
I have tried the above by putting user='+oc ...still not working .
Here actually opened_by field will have Username but when i am declaring variable as below
var oc = gs.getUserID('current.parent.opened_by');
i think it's not gettingUserID with code declaration ....is there any ways to get userID of 'opened_by' field from Impact table ?!
and Please let me know if have any other solutions otherthan my code for both line no 3 & line no 5 .