Skip to main content

ServiceNow Workspace list actions

 see

https://docs.servicenow.com/bundle/tokyo-platform-user-interface/page/administer/workspace/task/create-a-configurable-workspace-list-action.html 

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('d95447ce1b973010987d1fc3b24xxxx', 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); }

 

Comments

Popular posts from this blog

ServiceNow check for null or nil or empty (or not)

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 )){

Get URL Parameter - server side script (portal or classic UI)

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 ); }