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

URL link in addInfoMessage

var ga=new GlideAjax('gld_HR_ajax'); ga.addParam('sysparm_name', 'checkEmployeeNumber_hrProfile'); ga.addParam('sysparm_hrprofilenumber', g_form.getValue('number')); ga.addParam('sysparm_employeenumber', newValue); ga.getXMLAnswer(function(answer) { if (answer!='undefined' && answer!=''){ var navURL="<a style='text-decoration:underline;color:blue' href=hr_profile.do?sysparm_query=number=" + answer + ">" + answer + "</a><img width='3' src='images/s.gif'/>"; var sMsg='The employee number entered already exists on another HR Profile ' + navURL; //alert(sMsg); g_form.showErrorBox('employee_number', 'error - please check'); g_form.addInfoMessage(sMsg); } });

GlideRecord setValue

setValue(String name, Object value) Sets the specified field to the specified value. Normally a script would do a direct assignment, for example,  gr.category = value . However, if in a script the element name is a variable, then  gr.setValue(elementName, value)  can be used. When setting a value, ensure the data type of the field matches the data type of the value you enter. This method cannot be used on journal fields. If the value parameter is null, the record is not updated, and an error is not thrown https://developer.servicenow.com/app.do#!/api_doc?v=madrid&id=r_GlideRecord-setValue_String_Object