ServiceNow Workspace list actions
see
bulk create incidents from interactions
(c) Jithender Nayini
var canCreateIncident = false; if ((current.isNewRecord() && current.canCreate()) || (!current.isNewRecord() && current.canWrite())) canCreateIncident = current.update(); else canCreateIncident = true; if (canCreateIncident) { var inc = new GlideRecord("incident"); inc.initialize(); inc.caller_id = current.opened_for; inc.short_description = current.short_description; inc.description = current.u_description; inc.service_offering = current.u_service_offering; inc.contact_type = current.type; if (gs.getProperty("com.snc.incident.create_from_interaction.save") === 'true') { inc.work_notes = gs.getMessage('Incident created from Interaction {0}', current.number); var incSysId = inc.insert(); if (incSysId) { if (gs.getProperty('com.snc.incident.create_from_interaction.copy_attachments' , false) === 'true') { var serviceInteractionUtils = new global.ServiceInteractionUtils(); serviceInteractionUtils.copyAttachments(current, inc); } var interactionRelatedGR = new GlideRecord("interaction_related_record"); interactionRelatedGR.initialize(); interactionRelatedGR.interaction = current.sys_id; interactionRelatedGR.document_table = 'incident'; interactionRelatedGR.document_id = incSysId; interactionRelatedGR.insert(); } } action.openGlideRecord(inc); }
create a general request from interactions
where the general request is a catalog item
var canCreateRequest = false; if ((current.isNewRecord() && current.canCreate()) || (!current.isNewRecord() && current.canWrite())) canCreateRequest = current.update(); else canCreateRequest = true; if (canCreateRequest) { var cartId = GlideGuid.generate(null); var cart = new Cart(cartId); var item = cart.addItem('d95447ce1b973010987d1fc3b24*xxxx*', 1); cart.setVariable(item, "onbehalfof_flag", 'Yes'); cart.setVariable(item, "on_behalf_of", current.opened_for); cart.setVariable(item, "email", current.opened_for.email); cart.setVariable(item, "short_description", current.short_description); cart.setVariable(item, "description", current.u_description); cart.setVariable(item, "related_interaction_record", current.sys_id); cart.setVariable(item, "service_or_service_offering", current.u_service_offering); cart.setVariable(item,"contact_type",current.type); cart.setVariable(item, "assignment_group", current.u_service_offering.support_group); cart.setVariable(item,"minimum_data_set",current.u_service_offering.u_minimum_data_set); var rc = cart.placeOrder(); var reqRecord = new GlideRecord('sc_request'); reqRecord.get(rc.sys_id); reqRecord.requested_for = current.opened_for; reqRecord.update(); if (rc.sys_id) { var interactionRelatedGR = new GlideRecord("interaction_related_record"); interactionRelatedGR.initialize(); interactionRelatedGR.interaction = current.sys_id; interactionRelatedGR.document_table = 'sc_request'; interactionRelatedGR.document_id = rc.sys_id; interactionRelatedGR.insert(); } action.openGlideRecord(rc); }
Haven't tested these all recently within global/local scopes, so feel free to have a play! option 1 use an encoded query embedded in the GlideRecord , e.g. var grProf = new GlideRecord ( 'x_cls_clear_skye_i_profile' ); grProf . addQuery ( 'status=1^ owner=NULL ' ); grProf . query (); even better use the glideRecord addNotNullQuery or addNullQuery option 2 JSUtil.nil / notNil (this might be the most powerful. See this link ) example: if ( current . operation () == 'insert' && JSUtil . notNil ( current . parent ) && ! current . work_effort . nil ()) option 3 there might be times when you need to get inside the GlideRecord and perform the check there, for example if the code goes down 2 optional routes depending on null / not null can use gs.nil : var grAppr = new GlideRecord ( 'sysapproval_approver' ); var grUser = new GlideRecord ( 'sys_user' ); if ( grUser . get ( 'sys_id' , current . approver )){
Classic UI : var sURL_editparam = gs . action . getGlideURI (). getMap (). get ( ' sysparm_aparameter ' ); if ( sURL_editparam == 'true' ) { gs . addInfoMessage ( 'parameter passed ); } Portal : var sURL_editparam = $sp . getParameter ( " sysparm_aparameter " ); if ( sURL_editparam == 'true' ) { gs . addInfoMessage ( 'parameter passed ); }
Call a script include to apply a reference qualifier on a catalog item variable: - variable reference qualifier dependent on another variable selection, in this case a variable referencing sys_user (requested_for) On the catalog item form. variable name to apply ref qual filter : retail_equipment variable reference qualifier (on cmdb table ): javascript : new refqual_functions (). lostStolen_getAssignedCIs (); client-callable script include ( refqual_functions) function : lostStolen_getAssignedCIs : function (){ //--called from variable set client script, for lost/stolen request (service catalog) gs . log ( current . variables . requested_for , 'retail_lostStolen_getAssignedCIs' ); return ( 'install_statusNOT IN8,7owned_by=' + current . variables . requested_for ); //owned_by=1269b79937f1060041c5616043990e41install_statusNOT IN8,7 },
http://www.cloudminus89.com/2022/08/servicenow-workspace-list-actions.html