Need to convert catalog variables into JSON and store it as a variable to use it in workflow

redth
Giga Expert

Hi,

I need to convert catalog variables (application, application process, environment, versions and components) selected by the user into JSON format so that I can use it for deployment in the workflow.

Below is the format:

{
  "application": "hello Application",
  "applicationProcess": "hello App Process",
  "environment": "helloDeploy",
  "versions": [{
    "version": "1.0",
    "component": "helloWorld"
  }]
}
Can you assist me in implementing this requirement?
1 ACCEPTED SOLUTION

SanjivMeher
Kilo Patron
Kilo Patron

Do this

 

var test = { "application": current.variables.var1 , "applicationProcess":current.variables.var2, "environment":current.variables.var3, "versions": [{ "version": "1.0", "component": "helloWorld" }] }


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

5 REPLIES 5

SanjivMeher
Kilo Patron
Kilo Patron

Do this

 

var test = { "application": current.variables.var1 , "applicationProcess":current.variables.var2, "environment":current.variables.var3, "versions": [{ "version": "1.0", "component": "helloWorld" }] }


Please mark this response as correct or helpful if it assisted you with your question.

redth
Giga Expert

Hi Sanjiv,

Thanks for responding.

But the JSON objects should be in double quotes whereas quotes can't be given for current.variables.var1 and current.variables.var2. So, does this works?

Yes. It will. 100%


Please mark this response as correct or helpful if it assisted you with your question.

Hi Sanjiv,

It's working perfectly. But I have one question. This is the script I have used in workflow.

var app = current.variables.app_name;
var appprocess = current.variables.app_process_name;
var appenv = current.variables.env;
var JSONver = [];
var JSONcomp = [];

var JSONresponse = JSON.parse(current.variables.storeDetails);
for(var i=0; i<JSONresponse.table.rows.length; i++){
JSONver.push(JSONresponse.table.rows[i].row[1]);
JSONcomp.push(JSONresponse.table.rows[i].row[0]);

workflow.scratchpad.JSONver = JSONver;
workflow.scratchpad.JSONcomp = JSONcomp;

var JSONstring = { "application": '' + app , "applicationProcess": '' +appprocess, "environment" : '' +appenv, "versions": [{ "version": JSONver, "component": JSONcomp }] };
}
var test = JSON.stringify(JSONstring);

gs.log('workflow' + test);

 

and it's giving me output in the following format:

{"application":"GBD_Demo",

  "applicationProcess": "DBmaestro Deployment",

   "environment": "QA_Env_1",

    "versions":[{

"version":["100.122", "122.34"],

"component":["Database","GBD_Demo"]

}]

}

 

Whereas I need the output in the following format:

{"application":"GBD_Demo",

  "applicationProcess": "DBmaestro Deployment",

   "environment": "QA_Env_1",

    "versions":[{

"version":"100.122",

"component":"Database",

},

{

"version":"122.34",

"component":"GBD_Demo",

}]

}

Can you please let me know how to achieve the above format?