Bootstrap FreeKB - ServiceNow - Auto Populate
ServiceNow - Auto Populate

Updated:   |  ServiceNow articles

Let's say you are creating a form in ServiceNow and you want to auto populate a input form field. For example, after selecting a CMDB Business Service then auto populate Assignment Group.

 

In this example, the CMDB Business Service input form would be a Reference that would get a CMDB Business Service from the cmdb_ci_service table.

 

And then the Assignment Group input form field would auto populate the assignment group name from the selected CMDB Business Service.

 

Notice also in this example that the Assignment Group input form field is read only. This is because we do not want to allow users to change the assignment group value since it auto populates based on the CMDB Business Service. In this scenario, a UI Policy is used to set assignment_group to read only.

 

It is noteworthy that the assignment_group input form field must NOT be mandatory in order for the UI Policy to be able to set the input form field to read only.

 

It may be possible that the CMDB Business Service does not have an Assignment Group. A client side script can be used to display an error message if the CMDB Business Service does not have an Assignment Group.

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}

	// 1 second delay as it takes a moment for assignment_group to populate with a value
	setTimeout(function() {
		var assignment_group = g_form.getValue('assignment_group');
		assignment_group = assignment_group.toString().trim();

		if ( assignment_group == "" ) {
			g_form.addErrorMessage("The CMDB Business Service you selected does not have an Assignment Group");
		}
	}, 1000);
}

 

A client side script can also be used to prevent the user from being able to submit the form if the CMDB Business Services does not have an Assignment Group.

function onSubmit() {
    if (g_form.getValue('assignment_group') == '') {
        g_form.addErrorMessage('The CMDB Business Service you selected does not have an Assignment Group');
        return false;
    }
}

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 3f77af in the box below so that we can be sure you are a human.