cancel
Showing results for 
Search instead for 
Did you mean: 

SAP SPA How to reference input parameter from Custom Script object in script?

Ron_Hagan
Product and Topic Expert
Product and Topic Expert
0 Kudos

I have partial success!  If I hard-code the period in the http request body in the custom script, it works.  What I need to be able to do is to reference the period in the Input parameter and set it inside the script.  Here is the script as I have it now.

let options = {
    'method': 'POST',
    'headers': { 'Content-type': 'application/json', 'accept': 'application/json' },
    'body': JSON.stringify({ Command: 'PipelineRun', StageType: 'CompensateAndPay',
    TraceLevel: 'status', ProcessingUnit: 'Unassigned', UserId: 'Administrator',
    RunMode: 'full', Period: { Name: 'June 2022' }, CalendarName: 'Main Monthly Calendar' }),
    'responseType': 'json', // parse the body of the result as a JSON object
    'resolveBodyOnly': true // get only the body of the response
};
return options;
 
There is an Input Parameter called PeriodName that I need to pass into the body for the Period Name (June 2022).
I've tried several things to reference the parameter but nothing seems to work.  And for some reason, I 
ronhagan_0-1708717130619.png

I'm not sure if I'm trying to do something that can't be done or if there is a work-around to get the HTTP Request syntax correct.

Thanks!

Ron

Accepted Solutions (0)

Answers (1)

Answers (1)

Ron_Hagan
Product and Topic Expert
Product and Topic Expert
0 Kudos

I think I figured out how to do it (but I do have one question).  Here is what I now have in the custom scripts:

-----------------------------------------------------------------------------

let pName = PeriodName;

let options1 = "'method': 'POST', 'headers': {'Content-type': 'application/json', 'accept': 'application/json'}, 'body': JSON.stringify({Command: 'PipelineRun', StageType: 'CompensateAndPay', TraceLevel: 'status', ProcessingUnit: 'Unassigned', UserId: 'Administrator', RunMode: 'full', Period: {Name: '" + pName + "'}, CalendarName: 'Main Monthly Calendar'}), 'responseType':'json', 'resolveBodyOnly':true ";

let options = "{" + options1 + "}";

return options;

--------------------------------------------------------------------------------

This does work but I would like to have it formatted so that it's easier to read.  Unfortunately, if I try to format it by putting in carriage returns, it fails.  Is there another way to do this?  It's functional, which is great and if there isn't a way then I'm good with that.

Thanks!

Ron