System Property throwing error

Hemant Kumar Ch
Kilo Sage

Hello Team

 

We are using Below Scripts but the script throwing an error message in Service portal

 

Not allowed to update the property : property name 

 

 

var GRPSYS_ID = 'd625dccec0a8016700a222a0f7900d06'; //Put the sys_id of the assignment group (or groups comma separated) here. Or set this in a system property and grab it here.
	var lstAssigned = gs.getProperty("rr.last_assigned_to"); //Get the sys_id of the user most recently assigned to by this rule.

	//Make an array of all users in the group(s), ordered alphabetically by name:
	var userList = [];
	var userHasGroup = new GlideRecord('sys_user_grmember');
	userHasGroup.addQuery('available', true);
	userHasGroup.addQuery('group', 'IN', GRPSYS_ID);
	//userHasGroup.orderBy('user.name');
	userHasGroup.query();
	while (userHasGroup.next())
		userList.push(userHasGroup.getValue('user'));

	var nextUserIndex = userList.indexOf(lstAssigned) + 1;
	if (nextUserIndex == userList.length)
		nextUserIndex = 0;
	var nextUser = userList[nextUserIndex];
	current.assigned_to = nextUser;
	gs.setProperty("rr.last_assigned_to", nextUser); //Update the property with the sys_id of the user most recently assigned to by this rule.

 

 

This is for Round Robin ,Any thoughts how to fix this 

19 REPLIES 19

Hello Abhijit

I have Created a custom table and with two string field name and value 

Name (Default) : Last Assigned To

Value(Default) :

 

But the script is not working ,Could you please check where it going wrong

 

var GRPSYS_ID = 'd625dccec0a8016700a222a0f7900d06'; //Put the sys_id of the assignment group (or groups comma separated) here. Or set this in a system property and grab it here.
	//var lstAssigned = gs.getProperty("rr.last_assigned_to"); //Get the sys_id of the user most recently assigned to by this rule.
     var getLstAssigned = new GlideRecord('u_rr_last_assigned');
	getLstAssigned.addQuery("u_name","last Assigned To");
	getLstAssigned.query();
	if(getLstAssigned.next()){
		var lstAssigned = getLstAssigned.getValue('u_value');
	}
	
	
	//Make an array of all users in the group(s), ordered alphabetically by name:
	var userList = [];
	var userHasGroup = new GlideRecord('sys_user_grmember');
	userHasGroup.addQuery('available', true);
	userHasGroup.addQuery('group', 'IN', GRPSYS_ID);
	//userHasGroup.orderBy('user.name');
	userHasGroup.query();
	while (userHasGroup.next())
		userList.push(userHasGroup.getValue('user'));

	var nextUserIndex = userList.indexOf(lstAssigned) + 1;
	if (nextUserIndex == userList.length)
		nextUserIndex = 0;
	var nextUser = userList[nextUserIndex];
	current.assigned_to = nextUser;
	//gs.setProperty("rr.last_assigned_to", nextUser); //Update the property with the sys_id of the user most recently assigned to by this rule.
var grProperty=new GlideRecord("u_rr_last_assigned");
     if(grProperty.get("u_name","last Assigned To")){
grProperty.u_value=nextUser;
grProperty.update();
}

You have to create one record manually in custom table, sys id of the newly created record will need to be used in script as shown below in if condition. Your script will update the same record whenever necessary. 

 

var GRPSYS_ID = 'd625dccec0a8016700a222a0f7900d06'; //Put the sys_id of the assignment group (or groups comma separated) here. Or set this in a system property and grab it here.
	//var lstAssigned = gs.getProperty("rr.last_assigned_to"); //Get the sys_id of the user most recently assigned to by this rule.
     var getLstAssigned = new GlideRecord('u_rr_last_assigned');
	getLstAssigned.addQuery("u_name","last Assigned To");
	getLstAssigned.query();
	if(getLstAssigned.next()){
		var lstAssigned = getLstAssigned.getValue('u_value');
	}
	
	
	//Make an array of all users in the group(s), ordered alphabetically by name:
	var userList = [];
	var userHasGroup = new GlideRecord('sys_user_grmember');
	userHasGroup.addQuery('available', true);
	userHasGroup.addQuery('group', 'IN', GRPSYS_ID);
	//userHasGroup.orderBy('user.name');
	userHasGroup.query();
	while (userHasGroup.next())
		userList.push(userHasGroup.getValue('user'));

	var nextUserIndex = userList.indexOf(lstAssigned) + 1;
	if (nextUserIndex == userList.length)
		nextUserIndex = 0;
	var nextUser = userList[nextUserIndex];
	current.assigned_to = nextUser;
	//gs.setProperty("rr.last_assigned_to", nextUser); //Update the property with the sys_id of the user most recently assigned to by this rule.
var grProperty=new GlideRecord("u_rr_last_assigned");
     if(grProperty.get("sys_id_of_newly created record")){
grProperty.u_value=nextUser;
grProperty.update();
}

 

 

 

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Hello Abhjit

As I created a Manual record in a custom table with the sys id as one user and update that record sysid in the script but the ticket is going to only one user and it is not updating the value in the custom table 

 

it is not going in Circular pattern as like before 

Yes, custom table is storing last assigned to value but how you identify new last assigned to user? what is requirement/logic to update new last assigned to user?

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Hello Abhijit 

 

I have updated the random user sysid in the value field as last assigned next time onwards business rule should update and go on