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

yes...but my task is to acheive in script include + client script....

can you just help me for this part...i have tried but output is undefined

Hi,

Is that a business requirement to achieve it using Script Include + Glide Ajax + Client Script?

Because I believe the approach mentioned of display business rule is best here

But if you still want to achieve it can you share the script how you are calling it and what error you are getting?

Regards
Ankur

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

SCRIPT INCLUDE:----
var BBOX_Mapping_Assignedto = Class.create();
BBOX_Mapping_Assignedto.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    AssignedtoMapping: function() {
       var wotsysid = this.getParamater('sysparm_task');
		gs.addInfoMessage(wotsysid);///---"undefined"----
        var wot = new GlideRecord("task");
        wot.addQuery('sys_id', wotsysid);
        wot.query();
		//gs.addInfoMessage('test');
        if (wot.next()) {
            gs.addInfoMessage(wot.assigned_to);
			gs.addInfoMessage(gs.getUserID());
            if (wot.assigned_to == gs.getUserID()) {
                //gs.addInfoMessage(wot.assigned_to);
                return wot.assigned_to;
            }
        }
    },
	

CLIENT SCRIPT ON LOAD:---
function onLoad() {
   //Type appropriate comment here, and begin script below
	alert(g_form.getValue('task'));///---"task id"---
	var taskid = g_form.getValue('task');
	var ga = new GlideAjax('BBOX_Mapping_Assignedto');
	ga.addParam('sysparm_name','AssignedtoMapping');
	//g_form.addInfoMessage(g_form.getValue('sys_user'));
	ga.addParam('sysparm_task',taskid);
	ga.getXMLAnswer(callBack);
	
	function callBack(answer)
	{
		alert(answer);//----"null"-----
		g_form.setValue('user',answer);
	}   
}

the above code i have tried...

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

 

Hello Pravallika,

Did you have a chance to read this? 

 

- Pradeep Sharma