Skip to content

Instantly share code, notes, and snippets.

@hawkerboy7
Created February 13, 2018 17:27
Show Gist options
  • Save hawkerboy7/09c87e433559b455cd82a007e67da80a to your computer and use it in GitHub Desktop.
Save hawkerboy7/09c87e433559b455cd82a007e67da80a to your computer and use it in GitHub Desktop.

SNOW client-side

Client-side requests must all be made using GlideAjax with a callback function. Using .getXMLWait() is not adviced anymore since it blocks the client-side execution thread. The SNOW helper makes it possible to write the complete request as a simple one-liner.

Usage

SNOW.get(scriptInclude,functionName,sysParamObj,cb);

scriptInclde [string] The name of the ScriptInclude you are refering to.
functionName [string] The name of function in the ScriptInclude you want to execute.
sysParamObj [object] Object in which the key name is used as the sysparm_#{key} variable.
cb [function(err,data)] The call back function which gets executed when the response from the server comes back. It may contain an error (first argument) and it may contain data (second argument).

Example

function onLoad(control, oldValue, newValue, isLoading, isTemplate) {

	// SN standard check
	if (isLoading || newValue === "") { return; }

	// Check if the assignment group has a value
	if (g_form.getValue("u_assignment_group") !== "") { return; }

	// Retrieve the provided user's groups
	SNOW.get("[Prefix]_Call", "getGroupsOfUser", {id : g_form.getValue("opened_by")}, function(err, data) {

		// Log the error if found
		if (err) { return console.log(err); }

		// Fill the group if the provided user only has one group
		if (data.groups.length === 1) {

			// Set the assigment group since there is only one group the user is a member of
			g_form.setValue("u_assignment_group", data.groups[0]);

		} else {

			// Multiple options are available the user must choose one
			g_form.setMandatory("u_assignment_group", true);
		}

	});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment