Source field changes specifically on workspace

sonalpriyanka95
Giga Expert

I want when an request Item is created specially on workspace and Service desk agent clicks on SAVE then Source (contact_type) field should be Email, other wise when uses service portal then Source (contact_type) field should be Portal , tried through Client script it's working fine for portal but not on workspace.

 

Any suggestion how to acheive 

1 ACCEPTED SOLUTION

Tanushree Maiti
Tera Patron

Hi @sonalpriyanka95 

 

You can  replace your onSubmit Client Script with a Before-Insert Business Rule.

  • Name: Set Contact Type by Source
  • Table: Requested Item (sc_req_item)
  • When: Before
  • Insert: Checked
  • Update: Unchecked
  • Condition: contact_type is empty

 

(function executeRule(current, previous /*null when async*/) {

    var action = gs.action.getGlideURI().toString();

    var isWorkspace = action.indexOf('$sw.do') > -1 || action.indexOf('agent_workspace') > -1;

    if (isWorkspace) {

        current.contact_type = 'email'; 

    } else {

        current.contact_type = 'portal'; 

    }

 

})(current, previous);

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron

@sonalpriyanka95 

how are the agents creating RITM from workspace?

are they submitting request from workspace?

share your screenshots, script and form etc

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

sonalpriyanka95
Giga Expert

whener we recieve any email through interaction we have given option to create req item

@sonalpriyanka95 

then you can try to use onLoad client script on sc_req_item and see if the URL contains workspace name, if yes then set the contact type

did you try above approach?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

I tried that but somehow  it's breaking for service portal then ,

I want particularly for sow workspaces it should be email , rest for service portal as Portal..

Please find the script below 

 

function onSubmit() {
    alert("running");
   //Type appropriate comment here, and begin script below
  // g_form.setValue("contact_type","portal");
    //g_form.save();

    if (window.NOW && window.NOW.sp) {
        g_form.setValue('contact_type', 'portal');
    } else {
        g_form.setValue('contact_type', 'email');
    }

}