Extract Value from Query String
Extracts the value of the specified parameter from the serialized query-string (e.g. “a=123&b=456”) and stores it as workflow data.
2018 © Questetra, Inc. (MIT License)
Configs
  • A: Select STRING DATA for Query String *
  • B: Set Name of Parameter (e.g. ‘a’ “a=123&b=456”) * #{EL}
  • C: Select STRING/NUMERIC DATA for Extacted Value (update) *
Script
// About "serialize" or "Query String"
// - see https://api.jquery.com/serialize/


//////// START "main()" ////////
main();
function main(){

//// == Config Retrieving / 工程コンフィグの参照 ==
const dataIdA = configs.get( "conf_DataIdA" ) + "";
const dataIdC = configs.get( "conf_DataIdC" ) + "";
const paramName = configs.get( "conf_ParamName" ) + "";
// 'java.lang.String' (String Obj) to javascript primitive 'string'

//// == Data Retrieving / ワークフローデータの参照 ==
const queryString = engine.findDataByNumber( dataIdA ) + "";

//// == Calculating / 演算 ==
let paramValue = getParam(paramName, queryString);

//// == Data Updating / ワークフローデータへの代入 ==
if(paramValue === null){
  throw new Error( 'PARAMETER "' + paramName + '" is not found.' );
}
if( engine.findDataDefinitionByNumber( dataIdC ).matchDataType( "DECIMAL" ) ){
  var returnValue =  parseFloat( paramValue );
  engine.setDataByNumber( dataIdC, new java.math.BigDecimal(returnValue) );
}else{
  engine.setDataByNumber( dataIdC, paramValue );
}

} //////// END "main()" ////////


function getParam(name, querystr) {
  name = name.replace(/[\[\]]/g, "\\$&");
  var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)");
  var results = regex.exec(querystr);
  if (!results) return null;
  if (!results[2]) return '';
  return decodeURIComponent(results[2].replace(/\+/g, " "));
}

Download

Capture

Notes

  • It can be used such as for extracting necessary data from x-www-form-urlencoded which has received via Webhook
  • If there is no parameter name in the query string, automatic processing will result in an error
  • When storing it as numerical data, it follows the specifications of parseFloat ()
  • When storing it as numerical data, “314e-2” or “0.0314E + 2” will be “3.14”. (will be “3” when the format is decimal place 0 digit)
  • When storing as numeric type data, NaN and Infinite cause an error in automatic processing
%d bloggers like this: