- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2020 11:50 AM
Hello ,
I am looking to call Rest Message (outbound api) from workflow,i want to use Run Script and pass user from catalog item to the rest message in query parameter.
Actually i am looking to use POST rest message api and pass parameter from workflow or if you have any any other simple solution would be welcome.
am using workflow because i have some condition like sending notification after success(200) message or update ritm if not successful.
i saw some suggestions like using only client script calling script include but i am not sure how it would work for other conditions like sending notification because i am good at coding if its possible let me know i am looking for urgent solution.
Thanks in advance.
Solved! Go to Solution.
- Labels:
-
Integrations
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2020 12:05 PM
Hi Dashing,
The best practice is to use Run script activity to achieve this
Step 1: create a script include to initiate POST rest call and return the response
Step 2: create a run script activity in catalog item workflow, call the created script include
something like this by passing your current object, so that you can access and send variable values in the payload
var a = new scriptinclude().integration(current);
step 3: In the same run script activity, Write validations for returned value from script include stored in var a
something like
if (a == 200){
activity.result = 'success', //configure the output in conditions
current.work_notes = 'success';
}
if(a == 400){
activity.result = 'failure';
current.work_notes = 'failed';
}
Please mark helpful/correct if this helped
Thank you,
Vikram
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2020 12:05 PM
Hi Dashing,
The best practice is to use Run script activity to achieve this
Step 1: create a script include to initiate POST rest call and return the response
Step 2: create a run script activity in catalog item workflow, call the created script include
something like this by passing your current object, so that you can access and send variable values in the payload
var a = new scriptinclude().integration(current);
step 3: In the same run script activity, Write validations for returned value from script include stored in var a
something like
if (a == 200){
activity.result = 'success', //configure the output in conditions
current.work_notes = 'success';
}
if(a == 400){
activity.result = 'failure';
current.work_notes = 'failed';
}
Please mark helpful/correct if this helped
Thank you,
Vikram
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2020 01:27 PM
Good explanation but i have a question why we need to call through script include?because if we are calling directly "Rest Message" from run script and we pass variable in function.
My Workflow Run Script code:
try {
var r = new sn_ws.RESTMessageV2('REST API', 'Addmyfunction');
//override authentication profile
//authentication type ='basic'/ 'oauth2'
//r.setAuthenticationProfile(authentication type, profile name);
//set a MID server name if one wants to run the message on MID
//r.setMIDServer('MY_MID_SERVER');
//if the message is configured to communicate through ECC queue, either
//by setting a MID server or calling executeAsync, one needs to set skip_sensor
//to true. Otherwise, one may get an intermittent error that the response body is null
//r.setEccParameter('skip_sensor', true);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.message;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2020 02:19 PM
Thanks fie good suggestion but i have a question why we need to call script include?
could we directly call Rest Message from Run Script and pass variable?
This is my Run Script:
try {
var r = new sn_ws.RESTMessageV2('REST API', 'Addfuntiion');
//override authentication profile
//authentication type ='basic'/ 'oauth2'
//r.setAuthenticationProfile(authentication type, profile name);
//set a MID server name if one wants to run the message on MID
//r.setMIDServer('MY_MID_SERVER');
//if the message is configured to communicate through ECC queue, either
//by setting a MID server or calling executeAsync, one needs to set skip_sensor
//to true. Otherwise, one may get an intermittent error that the response body is null
//r.setEccParameter('skip_sensor', true);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.message;
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2020 10:26 PM