Help Needed: Creating Relationship Record in Another Table Using UI Action

nagaklv
Tera Contributor

Hello Experts,

We currently have a UI Action script that creates a Case record from an Interaction and establishes a mapping record in another table. The code works correctly in the following scenario:

  1. When the user clicks Create Case, it immediately creates a Case record and the associated mapping record – This is working as expected.

However, we would like to modify the behavior for the following scenario:

  1. When the user clicks Create Case, it should wait for the user to fill in some additional fields in a form. Only after submitting the form should it create the Case record and the mapping record – This is the behavior we are trying to achieve.------------------------------------------------------------------------------------------------------------------------------------

current.update();

var newRecord = new GlideRecord("sn_customerservice_case");
newRecord.initialize();

if (!gs.nil(current.account))
newRecord.setValue("account", current.getValue("account"));

if (!gs.nil(current.contact))
newRecord.setValue("contact", current.getValue("contact"));

if (!gs.nil(current.consumer))
newRecord.setValue("consumer", current.getValue("consumer"));

if (!gs.nil(current.short_description))
newRecord.setValue("short_description", current.getValue("short_description"));

if (!gs.nil(current.opened_for))
newRecord.setValue("internal_user", current.getValue("opened_for"));

if (GlidePluginManager.isActive('com.snc.service_organization') && !gs.nil(current.req_service_org))
newRecord.setValue("requesting_service_organization", current.getValue("req_service_org"));

if (GlidePluginManager.isActive('com.snc.csm_proxy_contacts') && !gs.nil(current.opened_for) &&
current.opened_for.sys_class_name == "sys_user" &&
new sn_csm_proxy_cont.ProxyContactHelper().isUserProxyContact(current.getValue("opened_for")))
newRecord.setValue("internal_contact", current.getValue("opened_for"));

if (current.getValue('type') == 'phone')
newRecord.setValue('contact_type', 'phone');
if (current.getValue('type') == 'chat')
newRecord.setValue('contact_type', 'chat');

// Insert the case
newRecord.insert();

// Open case record
action.openGlideRecord(newRecord);

// Track UI Action usage
var csmWorkspaceUAUtil = new sn_csm_workspace.CSMWorkspaceUAUtil();
csmWorkspaceUAUtil.createCaseClickInteraction();

// Copy attachments (if available)
var intRelUtil = new global.InteractionRelationshipUtil();
if (intRelUtil.copyAttachments !== undefined)
intRelUtil.copyAttachments(current, newRecord);

// Link interaction to case using your format
var gr = new GlideRecord("interaction_related_record");
gr.initialize();
gr.interaction = current.sys_id;
gr.document_table = 'sn_customerservice_case'
gr.document_id = newRecord.getUniqueValue();
gr.insert();

0 REPLIES 0