check whether the current logged in user is in assigned to field or part of additional assignee list

Pravallika9
Tera Expert

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..

 

1 ACCEPTED SOLUTION

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

 

View solution in original post

19 REPLIES 19

Ganesh Pardhe
Kilo Guru

Hello There,

you have to use below line in your code.

gs.getUser().isMemberOf('assigned_to')

 

for more information PFB link,

https://developer.servicenow.com/dev.do#!/reference/api/orlando/server_legacy/GUserAPI#GUser-isMembe...

 

regards,

Ganesh

thanks for reply but i want to check for addtional assignedd list too...

it will be helpful if you suggest in client script and script include

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you will require to have display business rule on the child form;

1) get the assigned_to and additional_assignee list

2) check if logged in user is present in these

3) if yes then set scratchpad variable as true/fale

4) use onload client script on child form and based on true or false auto-populate

Note: ensure you use proper field for parent field on child form; assigned to field, additional assignee list; user field on child form

Display BR:

var assignedTo  = current.parent.assigned_to;

var listArray = current.parent.additional_assignee.toString().split(',');

listArray.push(assignedTo.toString());

var arrayUtil = new ArrayUtil();

g_scratchpad.contains = arrayUtil.contains(listArray, gs.getUserID());

Client Script:

function onLoad(){

if(g_scratchpad.contains.toString() == 'true')

g_form.setValue('user_field', g_user.userID);

}

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

hi ankur,

Thanx for the reply

but user is not populating