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

Here is the updated code :

 

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;
      var grProperty=new GlideRecord("sys_properties");
     if(grProperty.get("name","rr.last_assigned_to")){
grProperty.value=nextUser;
grProperty.update();
}
	

 

I am assuming this updates system property once in while ( make sure you understand its performance issue)

 

Please mark answer as Correct or Helpful based on impact.

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

Hello Abhijit

I didn't expect it will be while ,Any user raised incident from Portal the assigned to get updated and it will update the property 

 

As per your exp do you suggest any alternative to avoid performance issues?

 

Looks like this operation executes for only one particular group which might have few days of delay at least. As an alternative you may need to create custom table to store last assigned to as suggested by Mark on below thread.

https://www.servicenow.com/community/now-platform-forum/is-there-any-alternative-for-available-for-g... 

 

However, many user have mentioned over community thread that they haven't faced any performance issue so far so you can go ahead with it, if you face any issue in future then you might think of using custom table approach is absolutely necessary (as 15 custom tables are free of cost, if you have crossed that count already then you might need to pay for new custom table)

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

Hello 

 

Could you please help me utilizing custom table solution 

 

What field should be in Table and what modification needed to be done in Script?

 

I think we can create free so I want to utilize some long-term solution 

 

You need to create new table with field 'Name' and 'Value'. It will have one record with 'Name' as 'last Assigned To' Value as 'your_last_assigned_to_user_sys_id'. You can glide into this table as we did for system property table and keep updating same record.

 

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