(Suggestion?) Replace template tokens after parsing?

Posted by matman on 26-Sep-2014 04:03

Is it possible to replace the {!...} template tokens with corresponding values after the script has been parsed? Right now only the template tokens manually entered in my script are replaced. I am trying to retrieve values more dynamically using arrays, generating the tokens during execution:

	var statusNameNmbr = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13"];
	var fields = [
		["bbs", "box", "email", "housenet", "jira", "letter", "final"]
	];

	var s1 = "{!web01_bbs}";
	var s2 = new String("{" + '\u0021' + "web" + statusNameNmbr[0] + "_" + fields[0][0] + "}");
	rbv_api.log("debug", "String #1: " + s1 + ", string #2: " + s2);

This logs "String #1: true, string #2: {!web01_bbs}", but as you may understand, I'd rather get the corresponding value (true / false for this checkbox).

All Replies

Posted by Orchid Corpin on 02-Oct-2014 15:14

I suggest of using "rbv_api.getFieldValue(objName, objId, fieldName)" instead and remove the {!} of your s2 and assign s2 to the "fieldName", here is the revised code.

var statusNameNmbr = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13"];
var fields = [
    ["bbs", "box", "email", "housenet", "jira", "letter", "final"]
];
 
var s1 = "{!web01_bbs}";
var s2 = "web" + statusNameNmbr[0] + "_" + fields[0][0];
var myField = rbv_api.getFieldValue("product1", {!id}, s2);
rbv_api.println(myField);

Hope this helps.

Regards,

Orchid

Posted by matman on 03-Oct-2014 06:29

It helps, but I actually forgot to mention that I was trying to achieve something like "{!" + fields[0][1] + "[tag:before]}"; . The reason I was trying to do it like that was because I wanted to retrieve the value when evaluating it, not before the evaluation. I wanted to expand the fields array up to 90 fields; retrieving 180 field values (current value and [tag:before] value) was a bit too much.

Posted by Orchid Corpin on 06-Oct-2014 10:56

I see, in that case just add "#before" to s2 (s2+"#before"), still make use of rbv_api.getFieldValue();

var statusNameNmbr = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13"];
var fields = [
    ["bbs", "box", "email", "housenet", "jira", "letter", "final"]
];
  
var s1 = "{!web01_bbs}";
var s2 = "web" + statusNameNmbr[0] + "_" + fields[0][0];
var myField = rbv_api.getFieldValue("product1", {!id}, s2+"#before");
rbv_api.println(myField);
return "BEFORE: "+myField + "NEW: "+{!web01_bbs};


Posted by matman on 07-Oct-2014 02:08

Thanks a lot! Didn't know that was possible because I thought rbv_api.getFieldValue() retrieves values stored in the database.

Posted by Orchid Corpin on 07-Oct-2014 11:44

Yes you can use that. Another tips, you can use another "#..."  suffix too, and can be use in the query.

rbv_api.getFieldValue("product1", {!id}, "fieldName#id");
rbv_api.getFieldValue("product1", {!id}, "fieldName#code");
rbv_api.getFieldValue("product1", {!id}, "fieldName#value");
rbv_api.selectValue("SELECT fieldName#code FROM product1 WHERE id={!id}");

Hope this helps.

Regards,

Orchid

Posted by romain.pennes@foederis.fr on 08-Oct-2014 02:59

Omg that is awesome:

rbv_api.getFieldValue("product1", {!id}, "fieldName#id");

rbv_api.getFieldValue("product1", {!id}, "fieldName#code");

rbv_api.getFieldValue("product1", {!id}, "fieldName#value");

rbv_api.selectValue("SELECT fieldName#code FROM product1 WHERE id={!id}");

I didn't know it was possible and I've spent 3 years using rbv_api.getCodeById / rbv_api.getIdByCode for no reason!

Thank you very much, I will definitely use these.

Kind regards,

Romain.

Posted by matman on 08-Oct-2014 06:27

Cool, good to know!

[mention:8358709d87ea4f06a7b6a0a79b0c6e01:e9ed411860ed4f2ba0265705b8793d05] didn't you use {!fieldName#suffix} before?

Posted by romain.pennes@foederis.fr on 08-Oct-2014 07:43

Hello,

Yes I did, but not in a getFieldValue or selectQuery call, I didn't know you could asked to be retrieved the code directely.

For instance, to retrieve a status code from a "distant record" (which I can't access using {!...} tokens), I would do:

var idStatus = rbv_api.getFieldValue('objName', recordId, 'status');

var codeStatus = rbv_api.getCodeById('objName', 'status', idStatus);

Orchid seems to be saying that you can do this instead:

var codeStatus = rbv_api.getFieldValue('objName', recordId, 'status#code');

Kind regards,

Romain.

This thread is closed