Page 1 of 1

variable script expression

Posted: Mon Feb 11, 2019 4:30 pm
by _Thibs_
Hello,

Curently I'm trying to use the variable script expression to define a choice of variable in a check point with an external metada (from a XML file).
Here is my code :

Code: Select all

function choixqte() {
	var Xpathquantites = [Metadata.Text:Path=''/gaxml/Quantités'',Dataset=''Xml'',Model=''XML''];
	var qauntites = job.getVariableAsString(Xpathquantites);
	var Xpathqrequiredquantity = [Metadata.Text:Path=''/gaxml/RequiredQuantity]'',Dataset=''Xml'',Model=''XML''];
	var requiredquantity = job.getVariableAsString(Xpathqrequiredquantity);					  
	if qauntites != "" {
		return qauntites;
}
	else { return requiredquantity; }
}
Switch returns a syntax error. Do you have any idea why ?

Thanks a lot in advance,

Re: variable script expression

Posted: Wed Feb 13, 2019 3:30 pm
by freddyp
Your Xpathquantites variable is not a string. The same for Xpathqrequiredquantity.
Even with that out of the way, it will still not work because you define a function but you do not call it. Add

Code: Select all

choixqte();
as the last line.
Alternatively, do not use a function, but in that case, and this is very important when using script expressions, you must not "return" a value, but simply "state" it:

Code: Select all

if qauntites != "" {
	qauntites;
} else {
	requiredquantity;
}

Re: variable script expression

Posted: Thu Feb 14, 2019 8:32 am
by r.zegwaard

Code: Select all

if qauntites != "" {
Place brackets in the if statement

Code: Select all

if (qauntites != "") {

Re: variable script expression

Posted: Fri Feb 15, 2019 9:16 am
by freddyp
Of course! Blind copy&paste error :oops: . Thanks.

Re: variable script expression

Posted: Wed Feb 20, 2019 11:45 am
by _Thibs_
Thanks I try that