I was hoping one of you may be able to help answer this scripting problem I am having
In one of my correlations I have a parameter being saved like so…
C_RegionValue = “N/A”
However when I need replace this value into one of my URL’s the N/A needs to change to N%2FA
So I am accomplishing this by:
if ( (strcmp("N/A", lr_eval_string("{C_RegionValue}"))) == 0){
lr_save_string("N%2FA", "C_RegionValue");
}
And this is working properly
do_create_RegionString.c(16): Notify: Saving Parameter "C_RegionValue = N/A".
do_create_RegionString.c(18): Notify: Parameter Substitution: parameter "C_RegionValue" = "N/A"
do_create_RegionString.c(19): Notify: Saving Parameter "C_RegionValue = N%2FA".
And I am even able to use that new parameter again in subsequent calls
lr_param_sprintf("temp_RString", "&vs_geoType_%d=Region&vs_geo_%d=%s", i, i,
lr_eval_string("{C_RegionValue}"));
do_create_RegionString.c(23): Notify: Parameter Substitution: parameter "C_RegionValue" = "N%2FA"
do_create_RegionString.c(23): Notify: Saving Parameter "temp_RString = &vs_geoType_6=Region&vs_geo_6=N%2FA".
But for some reason I am not able to use it on this call
lr_param_sprintf(lr_eval_string("{RegionString}"), lr_eval_string("{P_RGet_TmpVal}{temp_RString}"));
No errors it just never saves the new value, It substitutes everything properly but the value is never saved.
I know this section of the code is working because it does it 5 times prior to this call.
do_create_RegionString.c(35): Notify: Parameter Substitution: parameter "RegionString" = "PickAnyRegion_XL"
do_create_RegionString.c(35): Notify: Parameter Substitution: parameter "P_RGet_TmpVal" = "&vs_geoType_0=Region&vs_geo_0=Global (All Regions)&vs_geoType_1=Region&vs_geo_1=E&vs_geoType_2=Region&vs_geo_2=GC&vs_geoType_3=Region&vs_geo_3=I&vs_geoType_4=Region&vs_geo_4=NA&vs_geoType_5=Region&vs_geo_5=SA"
do_create_RegionString.c(35): Notify: Parameter Substitution: parameter "temp_RString" = "&vs_geoType_6=Region&vs_geo_6=N%2FA"
And it gets even weirder, If I do not change the value to N%2FA and leave it as N/A, or even if I use the same If statement and change the value to back to N/A everything works properly…
do_create_RegionString.c(35): Notify: Parameter Substitution: parameter "RegionString" = "PickAnyRegion_XL"
do_create_RegionString.c(35): Notify: Parameter Substitution: parameter "P_RGet_TmpVal" = "&vs_geoType_0=Region&vs_geo_0=Global (All Regions)&vs_geoType_1=Region&vs_geo_1=E&vs_geoType_2=Region&vs_geo_2=GC&vs_geoType_3=Region&vs_geo_3=I&vs_geoType_4=Region&vs_geo_4=NA&vs_geoType_5=Region&vs_geo_5=SA"
do_create_RegionString.c(35): Notify: Parameter Substitution: parameter "temp_RString" = "&vs_geoType_6=Region&vs_geo_6=N/A"
do_create_RegionString.c(35): Notify: Saving Parameter "PickAnyRegion_XL = &vs_geoType_0=Region&vs_geo_0=Global (All Regions)&vs_geoType_1=Region&vs_geo_1=E&vs_geoType_2=Region&vs_geo_2=GC&vs_geoType_3=Region&vs_geo_3=I&vs_geoType_4=Region&vs_geo_4=NA&vs_geoType_5=Region&vs_geo_5=SA&vs_geoType_6=Region&vs_geo_6=N/A".
Any thoughts or idea’s here?
EDIT:
Here is a better example
Action()
{
lr_save_string("N/A","C_RegionValue");
lr_save_string("XL_PickAnySearch", "RegionString");
lr_save_string("&vs_geoType_0=Region&vs_geo_0=test","temp_RString");
lr_save_string(lr_eval_string("{temp_RString}"), "XL_PickAnySearch");
/*
Lines 12-13 section will convert N/A into N%2FA, if left uncommented Line 20
will not save the string, if commented line 20 will save the string
*/
web_convert_param("C_RegionValue", "SourceEncoding=PLAIN",
"TargetEncoding=URL", LAST);
lr_param_sprintf("temp_RString", "&vs_geoType_%d=Region&vs_geo_%d=%s", 1, 1,
lr_eval_string("{C_RegionValue}"));
lr_param_sprintf("P_RTmpVal", "{%s}", lr_eval_string("{RegionString}"));
lr_param_sprintf("P_RGet_TmpVal", "%s", lr_eval_string(lr_eval_string("{P_RTmpVal}")));
lr_param_sprintf(lr_eval_string("{RegionString}"), lr_eval_string("{P_RGet_TmpVal}{temp_RString}"));
return 0;
}
EDIT: Could you be just missing the %s in the last call?
lr_param_sprintf(lr_eval_string("{RegionString}"),"%s", lr_eval_string("{P_RGet_TmpVal}{temp_RString}"));
I am not sure I understand your problem but I will try and give you couple of directions to go on.
1) lr_param_sprintf takes the parameter name as the first argument but it seems you are trying to send it an evaluated parameter in lr_param_sprintf(lr_eval_string("{RegionString}"), ...
Maybe you mean lr_param_sprintf("RegionString",...)?
2) The change of 'N/A' into 'N%2FA' is known as URL encoding. You can do it without the if with a built in function. See example:
lr_save_string("N/A","C_RegionValue");
web_convert_param("C_RegionValue", "SourceEncoding=PLAIN",
"TargetEncoding=URL", LAST);
lr_save_string("CA","C_RegionValue");
web_convert_param("C_RegionValue", "SourceEncoding=PLAIN",
"TargetEncoding=URL", LAST);
Output:
Action.c(3): Notify: Saving Parameter "C_RegionValue = N/A".
Action.c(5): web_convert_param started [MsgId: MMSG-26355]
Action.c(5): Notify: Saving Parameter "C_RegionValue = N%2FA".
Action.c(5): web_convert_param was successful [MsgId: MMSG-26392]
Action.c(9): Notify: Saving Parameter "C_RegionValue = CA".
Action.c(10): web_convert_param started [MsgId: MMSG-26355]
Action.c(10): Notify: Saving Parameter "C_RegionValue = CA".
Action.c(10): web_convert_param was successful [MsgId: MMSG-26392]
We recommend doing all the manipulations first and making the call to web_convert_param only when the final URL is ready.
Hope this helps.
Related
I have a pipeline parameter fed by a config file in SQL.
Sometimes that parameter will be empty, not NULL but just empty ('').
How do I write an expression that will evaluate the parameter to TRUE/FALSE(blank/not blank) that I can put into my IF activity?
Basic question but thanks a lot.
I tried
#pipeline().parameters.x = ''
but it just told me Parameter x = '' was not found .......
You can use the below expression in the if activity to evaluate a parameter is empty or not.
#empty(pipeline().parameters.ok)
Sample demonstration:
A sample parameter ok.
For example, purpose I have created a string variable which I will use inside if to check the output.
In if give the above expression.
Inside True activities I have given a set variable activity and gave some value and did the same inside false activities.
Output when the parameter value is not given(empty).
Output when we gave any value to the parameter
I've got a Jenkinsfile script in groovy which is processing a Java application's application.properties file, which I have just added to with
spring.main.banner-mode: off
In my script I read the application.properties file into a map in memory using a Jenkins add-in library yamlRead and then I output the value again into another file but it comes out as:
spring.main.banner-mode: false
That breaks my Java program on boot with a nasty spring boot error. The spring boot variable expects either OFF, FILE or CONSOLE.
I have no way to change yamlRead but I can change the output script which looks like this:
yaml.each {
key, value -> B: {
// some processing...
sh "echo '$base$key=$value' >> $file"
}
}
}
How can I determine if the map actually has the boolean type (which would be bad since I can't change it) or whether the undesired cast to boolean happens in myy echo >> file?
Or could I somehow force groovy not to infer the booleanness when it reads the input, perhaps with quotes around "off"?
Everything is working as expected. Groovy is not your problem its YAML. The YAML reference says that 'off' is interpreted as 'false' as you can see here
https://yaml.org/refcard.html
The Jenkins yamlRead reads 'off' and transforms it to a boolean with value 'false'.
as Thomas wrote: off is a reserved word in yaml format for boolean false
however you could quote it to force it to be a string:
spring.main.banner-mode: 'off'
in this case spring.main.banner-mode key will have a string value off
to check boolean false value you could use something like:
yaml.each {
key, value -> B: {
// some processing...
sh "echo '$base$key=${ value==false? 'off' : value }' >> $file"
}
}
PS:
instead of calling sh to append to a file one key-value you could use following code:
def values = yaml.collect{k,v-> "$k=$v"}.join("\n")
writeFile( file: file, text: values )
I have userevent script that I need to add a + 1 value to a field on edit.
This is what I have so far:
nlapiSubmitField('custbody1', + '1');
I am receiving an error, invalid expression. Please assist if you can.
Thanks
+ '1' is not valid JavaScript syntax.
You will need to retrieve the current value from custbody1 (presumably with a lookup), parse it as a Number, add 1 to the result, then that result is what you will pass to nlapiSubmitField.
You will need to store the returned value of nlapiGetFieldValue in a variable before using nlapiSetFieldValue. Something like:
var x = nlapiGetFieldValue('field1');
nlapiSetFieldValue('field1', parseInt(x) +1);
We need to get the value of dynamically constructed variables.
What I mean is we have a variable loaded from a property file called data8967677878788node. So when we run echo $data8967677878788node we get the output test.
Now in data8967677878788node the number part 8967677878788 needs to be dynamic. That means there could be variables like
data1234node
data346346367node
and such.
The number is an input argument to the script. So we need something like this to work
TESTVAR="data`echo $DATANUMBER`node"
echo $$TESTVAR #This line gives the value "test"
Any idea on how this can be accomplished
You can use BASH's indirect variable expansion:
data346346367node='test'
myfunc() {
datanumber="$1"
var1="data${datanumber}node"
echo "${!var1}"
}
And call it as:
myfunc 346346367
Output:
test
Your code is actually already pretty close to working, it just needs to be modified slightly:
TESTVAR="data`echo $DATANUMBER`node"
echo ${!TESTVAR}
If $DATANUMBER has the value 12345 and $data12345node has the value test then the above snippet will output test.
Source: http://wiki.bash-hackers.org/syntax/pe#indirection
I am generating strings with the names of existing variables. I want to use the strings to create a variable set to the VALUE of the existing variable, but I can't figure out how to achieve this.
Put another way if this helps:
A calling routine sends strings "abc" "cde" etc... Each string is the first several characters of a path variable I've already set. I then append "path" to the passed string to create the full name of the existing variable (e.g., %abcpath%) Now I want to get the value of %abcpath% and put it into a variable I can use it in the current routine.
Thanks for any help.
Here is part of the code I have:
SET abcPath=c:\path_to_abc_dir
SET cdePath=c:\path_to_cde_dir
call :names abc cde ...
:names
For %%G in (%*) do (
set name=%%G
:: Append "path" to name from calling routine
set namepath=!name!path
echo "!namepath!"
:: 1st time through namepath is "abcPath"
:: How to now set a var to the VALUE of %abcPath% set above?
::these don't work:
set dirpath=%%namepath%%
set dirpath=!%%namepath%%!
set dirpath=!%namepath%%%amepath%%!
set dirpath=!!name!path:%dirpath%=%%dirpath%%!
::I want to do things with %dirpath% in this routine:
if not "!dirpath!"=="" (
cd !dirpath!
:: call subroutine to get the number of files in the directory
call :forhere
do other stuff with var dirpath ...
)
)
....
::these don't work:
set dirpath=%%namepath%%
^^........^^ Not a valid variable reference
set dirpath=!%%namepath%%!
^^........^^ Not a valid variable reference
set dirpath=!%namepath%%%amepath%%!
^........^ This has been parsed at start and has no value
set dirpath=!!name!path:%dirpath%=%%dirpath%%!
^^ ^..........................^ two "variables" start and end
Delayed expasion over a value obtained with delayed expansion does not have a obvious syntax, because this does not exist. It can not directly be done and other commands need to be used
....
set "name=%%G"
set "namepath=%%Gpath"
call set "dirpath=%%!namepath!%%"
echo !dirpath!
....
Why or how does it work?
When the line is parsed, the only variable referenced is namepath with delayed expansion. The double percent signs are a escaped percent sign. So the line is translated into
call set "dirpath=%abcpath%"
Now, the call is executed, generating a second parse of the line, obtaining the correct value
This can also be done as
for %%a in ("!namepath!") do set "dirpath=!%%~a!"
In this case, the value inside namepath variable is stored into the for replaceable parameter and used to obtain the value to assign to the dirpath variable
In both cases, two "parse" (in the logic sense) operations are done.
In the first solution the first parse extracts the value of namepath and the second parse (invoked by call command execution) uses this value as a variable name.
In the second solution, we first get the value inside namepath (first "parse") and then this value is used in a new delayed expansion operation to retrieve the value to assign to dirpath