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

@sonalpriyanka95 

why are you using onSubmit?

I suggested to use onLoad and normal client script on RITM table which won't impact the catalog item on portal

💡 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

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