- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2020 11:07 PM
My requirement is....
parent form---wm_task
child form--time_worked
if i create new child form it will autopopulate parent number....i want to autopopulate current logged in user in the "user" field only if that user is part of assigned to or additional assignee list in the parent form..
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 11:21 AM
Hello Pravallika,
Below please find the updated code. Replace your CS and Script Include with below code.
CS:
function onLoad() {
var taskid = g_form.getValue('task');
var ga = new GlideAjax('BBOX_Mapping_Assignedto');
ga.addParam('sysparm_name', 'AssignedtoMapping');
ga.addParam('sysparm_task', taskid);
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
if(answer == 'true')
g_form.setValue('user', g_user.userID);
}
}
Script Include:
var BBOX_Mapping_Assignedto = Class.create();
BBOX_Mapping_Assignedto.prototype = Object.extendsObject(AbstractAjaxProcessor, {
AssignedtoMapping: function() {
var wotsysid = this.getParameter('sysparm_task');
var wot = new GlideRecord("task");
wot.addQuery('sys_id', wotsysid);
wot.query();
if (wot.next()) {
var assignedTo = wot.assigned_to;
var list = wot.additional_assignee_list.toString().split(',');
list.push(assignedTo.toString());
var arrayUtil = new ArrayUtil();
return arrayUtil.contains(list, gs.getUserID());
}
},
type: 'BBOX_Mapping_Assignedto'
});
Let me know if that answered your question. If so, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.
- Pradeep Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 12:05 AM
Hi,
Can you share both the script?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 12:43 AM
on Display i am getting the assigned to part but i am not getting the additional assignee
client script on load:
function onLoad() {
if(g_scratchpad.contains.toString() == 'true')
g_form.setValue('user', g_user.userID);
}
Business rule--
(function executeRule(current, previous /*null when async*/) {
var assignedTo = current.task.assigned_to;
var list = current.task.additional_assignee_list.toString().split(',');
list.push(assignedTo.toString());
//list.indexOf(gs.getUserID());
var arrayUtil = new ArrayUtil();
g_scratchpad.contains = arrayUtil.contains(listArray, gs.getUserID());
gs.addInfoMessage(assignedTo);
if(assignedTo== gs.getUserID())
{
current.user = assignedTo;
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 02:09 AM
Hi,
mistake in your script; array name is list and not listArray
g_scratchpad.contains = arrayUtil.contains(list, gs.getUserID());
remove these lines as this is not required
gs.addInfoMessage(assignedTo);
if(assignedTo== gs.getUserID())
{
current.user = assignedTo;
}
final BR; I assume this is display business rule
(function executeRule(current, previous /*null when async*/) {
var assignedTo = current.task.assigned_to;
var list = current.task.additional_assignee_list.toString().split(',');
list.push(assignedTo.toString());
var arrayUtil = new ArrayUtil();
g_scratchpad.contains = arrayUtil.contains(list, gs.getUserID());
})(current, previous);
Can you share BR screenshot for confirmation
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 03:32 AM
hi,
thanx it is achievable now...
it will be more helpful if you help achieve the same from script include and client script...(GLIDE AJAX)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 04:47 AM
Hi,
Glad to hear. Please mark my response as ✅ correct & 👍 helpful
For this scenario display business rule is the best approach
Script Include + Client Script with GlideAjax will be taking more time as compare to display business rule approach; as script include will require query to parent table
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader