How can I Populate a custom field (Created by Team) with the Logged In User's Group Name

WazzaJC
Tera Expert

Hi Team,

I would really appreciate your help/guidance, I cannot work this out.

How can I configure a Business Rule or Client Script so that it populates a custom field I have created, with the Group/Group Names, that the currently logged in/opened by User belongs to, in the Incident form.

Custom Field is called: Created by Team (u_created_by_team) - this is where I want the User's Group Name or Names to populate to.

Source: Incident Form

Opened By field = Logged in User

I would like the Groups that the logged in user belongs to, to populate (onLoad) to the custom field (u_created_by_team), which I have set up as a sting field.

I assume this can be done by Business Rule or onLoad Client script but not sure how to do it.

Thanks ever so much - I have attached a screenshot showing my Incident Form with the fields on.

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@WazzaJC 

you can use display business rule on incident table and set the value

(function executeRule(current, previous /*null when async*/) {

	if(current.isNewRecord()){
		var groups = new global.ArrayUtil().convertArray(gs.getUser().getMyGroups());
		var arr = [];
		var gr = new GlideRecord("sys_user_group");
		gr.addQuery("sys_id", "IN", groups);
		gr.query();
		while (gr.next()) {
			arr.push(gr.getDisplayValue());
		}
		current.u_created_by_team = arr.toString();
	}

})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

7 REPLIES 7

Hi Ankur,

Quick follow up question please, if you don't mind, I would really appreciate final bit of guidance on this.

Your Display business rule is working perfectly, no issues, when I raise a New Incident within the Native UI View.

However when I select example 'Report an Issue' item from the Service Portal view, which is a Record Producer that then creates a related Incident in the system, once you press submit on the Portal, however this Incident that is created, is not triggering the same Display Business Rule, so the User's Group/Groups do not populate to the custom u_created_by_team field.

Do I need to also do a separate Business Rule or Client Script, to ensure it triggers when raising an Incident via the 'Report an Issue' Catalog Item (Record Producer) which is raised from the Service Portal ?

Would greatly appreciate your help.

Many thanks.

Kind Regards, Warwick

My initial thoughts are this is possible by way of Catalog Client Script on the 'Report An Issue' catalog item, so as to populate when onSubmit.

I just am not sure and what that Catalog Client Script would look like, if this is indeed the correct approach ?

Many thanks.

Hey Ankur,

Actually, great news - I managed to work it out myself !

I took your Script and input it into the Script body within the Report an Issue catalog item (record producer) and it all works perfectly. The script triggers when the Report an Issue is submitted from Service Portal and the Incident creates with the correct details populated.

So all is sorted - thanks again Ankur, much appreciated.

Kind Regards, Warwick