UI Builder - Client Script [Need assistance]

Community Alums
Not applicable

Hi All,

 

Requirement: When a user selects the application in the typeahead component then all the associated delegated developers should be listed in the stylized text or simple list component.

 

Reference blog: https://developer.servicenow.com/blog.do?p=/post/quebec-ui-builder-client-scripts/

 

Implementation details

Client state parameter: To hold the encoded query for the delegated developers to be queried from sys_user table

Pic 1.JPG

 

Script Include: To fetch the delegated developers sys_ids from the sys_user table

Pic 2.JPG

function include({imports}) { 
	return{
		getScopePermissionSetRoleAssignments: function(app_name){
			var arrUsers = [];
			var grScopePermissionRoles = new GlideRecord("sys_scope_permission_set_role_assignment");
			grScopePermissionRoles.addQuery("scope.name",${app_name});
			grScopePermissionRoles.query();
			while(grScopePermissionRoles.next()){
				var grUserRole = new GlideRecord("sys_user_has_role");
				grUserRole.addQuery("role",grScopePermissionRoles.role);
				grUserRole.query();
				while(grUserRole.next()){		
					arrUsers.push(grUserRole.user.sys_id.getDisplayValue());
				}
			}
			var arrUtil = new ArrayUtil();
			var arrDistinctUsers = arrUtil.unique(arrUsers);
			var listUsers = arrDistinctUsers.toString();
				
			return listUsers;
		}
	};
}

 

Client Script: Format the encoded query that needs to be passed in the simple list component or to be displayed in the stylized text for debugging purpose.

Sample one: sys_idIN65ced4221b4ad118728a7669cc4bcb74,25de1c221b4ad118728a7669cc4bcbaa,06c5ce4ddbd3f7004868776b8c96197f

Pic 3.JPG

function handler({api, event, helpers, imports}) {
    const sys_scope = api.elements.typeahead_1;
    const {getScopePermissionSetRoleAssignments} = imports['x_iem_xom_ws_manag.GetDelegatedUsers']();
    const userQuery = `sys_idIN${getScopePermissionSetRoleAssignments(sys_scope)}`;
    api.setState('delegated_developers',userQuery);
}

 

Typeahead: That invokes/executes the client script when a item selected from the typeahead component.

Pic 4.JPG

 

Stylized text component: Has a data binding to the client state parameter.

Pic 5.JPG

 

List - Simple component: has filer property data binding to client state parameter

Pic 6.JPG

 

Test Results

Client state parameter value doesn’t change. Seems client script is not invoked.

Pic 7.JPG

Could you please help me with this.

 

Thanks,

Raghu

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi All,

I've logged the logs to the console and then faced below error wrt UI Script Include. 

 

to string methodTypeError: Cannot destructure property 'getScopePermissionSetRoleAssignments' of 'imports.x_iem_xom_ws_manag.GetDelegatedUsers(...)' as it is undefined. in servicenow

 

Not very sure whether GlideRecord is supported in UI Script Includes or am I using the syntax wrongly for other script statements when specific to UI Script Includes.

Debugging tips in UI Builder (ServiceNow - Now Experience)

UI BUILDER - DATA RESOURCES

So, I removed this client script/script include and created Transform Data Resource.

Pic 8.png

Passed the client state parameter to the Data Resource:

 

Pic 9.JPG

Update the client state parameter from the typeahead component event handle:

RaghavendraMud_1-1681800346739.png

Finally the data resource output is referred in the simple list component.

RaghavendraMud_2-1681800406460.png

Magic worked.

 

Thanks,

Raghu

 

View solution in original post

2 REPLIES 2

Community Alums
Not applicable

@Ankur Bawiskar  @Aman Kumar S 

Could you please help with this one.

Community Alums
Not applicable

Hi All,

I've logged the logs to the console and then faced below error wrt UI Script Include. 

 

to string methodTypeError: Cannot destructure property 'getScopePermissionSetRoleAssignments' of 'imports.x_iem_xom_ws_manag.GetDelegatedUsers(...)' as it is undefined. in servicenow

 

Not very sure whether GlideRecord is supported in UI Script Includes or am I using the syntax wrongly for other script statements when specific to UI Script Includes.

Debugging tips in UI Builder (ServiceNow - Now Experience)

UI BUILDER - DATA RESOURCES

So, I removed this client script/script include and created Transform Data Resource.

Pic 8.png

Passed the client state parameter to the Data Resource:

 

Pic 9.JPG

Update the client state parameter from the typeahead component event handle:

RaghavendraMud_1-1681800346739.png

Finally the data resource output is referred in the simple list component.

RaghavendraMud_2-1681800406460.png

Magic worked.

 

Thanks,

Raghu