Possible to execute server side code from button on workspace?

JohnDF
Mega Sage

Hi everyone,

is it possible to execute server side code from a button on a dashboard in workspace via ui builder coding?

For example I want to achieve to add a button on this dashboard via ui builder (dont know if possible) and when I click on this button a server side code should execute a workflow via the workflow api with the sys_id of the open record and for example start a request of this or retire this software model.find_real_file.png

 

I know I can execute client script code via a component but can I trigger a workflow too?

 

Thanks for your help in advance.

1 ACCEPTED SOLUTION

Marc Mouries
ServiceNow Employee
ServiceNow Employee

Yes you can trigger a workflow via the page script. You will need to:

  1. In Flow Designer,
    1. create a Subflow
    2. then grab the code snippet from the Subflow editor
  2. In Scripted REST API,
    1. Create a REST API that calls the Subflow using the code snippet previously created
  3. In UIB,
    1. Add a page script that calls the REST API using the function snHttp
      1. See: Documentation helpers - helpers.snHttp(String url, Object options) 
      2. In the script you can refer to the current sysId by calling
         api.context.props.sysId
    2. Add a button
    3. Go to the click event and call the Page Script  

 

Typically the sys id can be retrieved by calling api.context.props.sysId however in your case you might be able to retrieve the sysId of the current record through a page property. 

 

 

View solution in original post

4 REPLIES 4

Marc Mouries
ServiceNow Employee
ServiceNow Employee

Yes you can trigger a workflow via the page script. You will need to:

  1. In Flow Designer,
    1. create a Subflow
    2. then grab the code snippet from the Subflow editor
  2. In Scripted REST API,
    1. Create a REST API that calls the Subflow using the code snippet previously created
  3. In UIB,
    1. Add a page script that calls the REST API using the function snHttp
      1. See: Documentation helpers - helpers.snHttp(String url, Object options) 
      2. In the script you can refer to the current sysId by calling
         api.context.props.sysId
    2. Add a button
    3. Go to the click event and call the Page Script  

 

Typically the sys id can be retrieved by calling api.context.props.sysId however in your case you might be able to retrieve the sysId of the current record through a page property. 

 

 

Hi @Marc Mouries thanks for reply.

This sounds good. I will try to work on this instruction you gave me. I come back if I have some problems.

Hi @Marc Mouries  

What do you mean with page property? And how can I pass the retrieved sysid to the subflow?

 

Thanks for your help.

hate to necro the thread,

but ...

what about 'putting backend logic on a smart button click, from agent mobile app' ??