-
-
Save wave-inguane/b04c924ae7ae2189447cb95759459a00 to your computer and use it in GitHub Desktop.
GlideForm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://www.programiz.com/javascript/forEach | |
//Returns an array off all empty mandatory fields | |
var fieldArray = g_form.getMissingFields(); | |
fieldArray.forEach(function(currentField, index, arr){ | |
//g_form.setMandatory("work_notes", false); | |
g_form.addInfoMessage("Field = "+currentField+" index = "+index); | |
}); | |
//Returns an array off all empty mandatory fields | |
var fieldArray = g_form.getMissingFields(); | |
fieldArray.forEach(function(field_name){ | |
g_form.setMandatory(field_name, false); | |
g_form.addInfoMessage("Field = "+field_name); | |
}); | |
function onSubmit() { | |
var action = g_form.getActionName(); | |
alert('You pressed ' + action); | |
} | |
===========================POPUP====================================== | |
function onChange(control, oldValue, newValue, isLoading, isTemplate) { | |
if (isLoading || newValue === '') { | |
return; | |
} | |
var group_name = ""; | |
var group_desc = ""; | |
var new_value = newValue; | |
var table_name = g_form.getTableName(); | |
if((g_form.getValue("work_notes") == "") && (table_name == "incident" || table_name == "sn_customerservice_case")){ | |
g_form.setMandatory("work_notes", false); | |
} | |
var arr = g_form.getMissingFields(); | |
if( (arr.length < 1 ) && (table_name == "incident" || table_name == "sn_customerservice_case") ){ | |
// new GlideAjax object referencing name of AJAX script include | |
var ga = new GlideAjax("GetGroupInformation"); | |
// add name parameter to define which function we want to call | |
// method name in script include will be getFavorites | |
ga.addParam("sysparm_name", "getGroupInfo"); | |
ga.addParam('sysparm_groupID', newValue); | |
// submit request to server, call ajaxResponse function with server response | |
ga.getXML(ajaxResponse); | |
} | |
function ajaxResponse(serverResponse) { | |
//build output to display on client for testing | |
var output = ""; | |
// get favorite elements | |
var favorites = serverResponse.responseXML.getElementsByTagName("favorite"); | |
for(var i = 0; i < favorites.length; i++) { | |
var name = favorites[i].getAttribute("name"); | |
var value = favorites[i].getAttribute("value"); | |
if(name == "group_name"){ | |
name = "Please confirm the reassignment of "+g_form.getValue("number") + " to "; | |
output += name + " : " + value + ""; | |
}else{ | |
output += ". *** GROUP RESPONSIBILITIES *** "+value ; | |
} | |
} | |
var msg = getMessage(output); | |
var dialog = new GlideModal('glide_modal_confirm', true, 400); | |
dialog.setTitle(new GwtMessage().getMessage('Confirmation')); | |
dialog.setPreference('body', new GwtMessage().format(msg)); | |
dialog.setPreference('focusTrap', true); | |
dialog.setPreference('onPromptComplete', confirm); | |
dialog.setPreference('onPromptCancel', cancel); | |
dialog.setPreference('buttonLabelComplete', new GwtMessage().getMessage('OK')); | |
dialog.setPreference('buttonLabelCancel', new GwtMessage().getMessage('Cancel')); | |
dialog.render(); | |
function confirm() { | |
g_form.setValue("assignment_group",newValue+""); | |
if(oldValue != newValue ) | |
g_form.setValue("work_notes", "Ticket reasigned by : "+ g_user.getFullName()); | |
g_form.save(); | |
} | |
function cancel() { | |
g_form.setValue("assignment_group",oldValue+""); | |
g_form.save(); | |
} | |
} | |
} | |
==================================Call Ajax===================================== | |
Client callable | |
var GetGroupInformation = Class.create(); | |
GetGroupInformation.prototype = Object.extendsObject(AbstractAjaxProcessor, { | |
getGroupInfo : function() { | |
var groupRecord = new GlideRecord("sys_user_group"); | |
groupRecord.get(this.getParameter('sysparm_groupID')); | |
// build new response xml element for result | |
var result = this.newItem("result"); | |
result.setAttribute("message", "returning group info"); | |
//add some favorite nodes with name and value attributes | |
this._addFavorite("group_name", groupRecord.getDisplayValue("name")); | |
this._addFavorite("group_description", groupRecord.getDisplayValue("description")); | |
// all items are returned to the client through the inherited methods of AbstractAjaxProcessor | |
}, | |
_addFavorite : function(name, value) { | |
var favs = this.newItem("favorite"); | |
favs.setAttribute("name", name); | |
favs.setAttribute("value", value); | |
}, | |
type: 'GetGroupInformation' | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment