I need to populate assigned to based on assignment group.

niveditakumari
Mega Sage

Hi, 

 

I need to populate assigned to based on assignment group. I have written this code and it is not working. 

niveditakumari_0-1707422000437.png 

niveditakumari_1-1707422097971.png

 

 

Please correct my code to make it work. 

 

Regards, 

Nivedita 

 

 

 

1 ACCEPTED SOLUTION

Rohini S Sane
Tera Guru

Hi @niveditakumari 

You can write below code in script include, its working on my PDI.

Script include code :

var populate_ag = Class.create();
populate_ag.prototype = {
    initialize: function() {
    },
myFunction : function(aggroup)
{
    var arr = [];
    var gr = new GlideRecord('sys_user_grmember');
    gr.addQuery('group',aggroup);
    gr.query();
    while(gr.next())
    {
arr.push(gr.user.toString());
    }
    return 'sys_idIN' + arr;
},
    type: 'populate_ag'
};
 
advanced ref qualifier script : javascript:new populate_ag().myFunction(current.u_group);
 
result.pngscriptinclude.pngadvref.png
 
Please mark helpful .
 
Thanks and Regards,
Rohini S Sane

View solution in original post

17 REPLIES 17

@niveditakumari  ,

Can you update the Script as below 

assignmentGrpUsers: function(usergroup) {

	var arryVal = [];
	if (usergroup!= '') {
		var grMember = new GlideRecord('sys_user_grmember');
		grMember.addEncodedQuery('group',usergroup);
		grMember.query();
		while (grMember.next()) {
			arryVal.push(grMember.getValue("user"));
		}
}
		return "sys_idIN" + arryVal.join();
	}

},

 

Add below Code in Advance Qualifier 

 javascript:assignmentGrpUsers(current.variables.assignment_group)

 

Attributes :

req_qual_elements=assignment_group

 

Regards,

Shyamkumar 

 

 

Please mark this as helpful and accept as a solution if this resolves your Ask.
Regards,

Shyamkumar

Hi @shyamkumar VK

 

It is not working. 

 

Regards, 

Nivedita 

 

 

Service_RNow
Mega Sage

Hi @niveditakumari 

1.  You need to make use of advanced reference qualifier in order to achieve this functionality.

In Referene Qualifier, you need to call script include where you can filter the groups and return the result to reference field assignment group.

You may refer this script,

Advanced Reference Qualifier Using a Script Include

Filter Assignment Group based on Assigned To

To know more about reference qualifiers,

https://docs.servicenow.com/bundle/washingtondc-platform-administration/page/script/server-scripting...

 

2nd Approach create Onload Client script:-

function onLoad() {
if(g_form.isNewRecord()){
  //Type appropriate comment here, and begin script below
  var gr = new GlideRecord('sys_user_group');
  gr.addQuery('name',"assignment group");   //as per my experience group name changes later during the time.
  gr.query();
  if(gr.next()){
  g_form.setValue('assignment_group',gr.sys_id);
  }
}
}

Please mark as Correct Answer and Helpful, if applicable.

Hi @Service_RNow

 

I have done that. It is not working. 

 

Regards, 

Nivedita 

 

 

Hi @niveditakumari 

 

 

try to use getDisplayValue() in your code.

var group = current.varaibles.assignment_group.getDisplayValue();
In Advance Reference Qualifier:
Javascript: new Script_Include().function_name();

 

Please mark as Correct Answer and Helpful, if applicable.