It's all about the answers!

Ask a question

DNG-RPE: How to print something if a custom attribute is blank


Shannon Struttmann (134) | asked Feb 12 '18, 11:44 a.m.

I have an attribute that has a unique identifier which was carried over from a previous requirements tool. I have figured out how to print that attribute correctly. What I want to do is, if that attribute is blank (for example if a new requirement is added without the attribute filled in) to print the DNG ID instead. I can't seem to figure out how to query on this. I have tried many many variations of 'if' statements for the following and nothing is working:

if (name=="ReqProID") {
    if (value.indexOf( "L2R") != -1) {
    value}
    else if (value.indexOf("L2R")== -1){
        "L2R" + identifier}}

Does anyone have advice on how to get the 'else if' portion working?

Thanks


Comments
Shannon Struttmann commented Feb 13 '18, 11:31 a.m.

Ok, my problem now is that I don't know how to query on the existence of an attribute. So in DNG, the ReqProID attribute is left blank. In this case, this means that RPE doesn't 'see' that attribute, and I can't query on the value. How can I say, "if ReqProID doesn't exist, print the identifier'? Any suggestions?

4 answers



permanent link
Donald Nong (14.4k313) | answered Feb 12 '18, 5:57 p.m.

I believe you should check whether the string is empty or null, rather than whether it contains a particular substring. You can see this interesting discussion on the other forum..
https://codereview.stackexchange.com/questions/5572/string-isnullorempty-in-javascript


permanent link
Kumaraswamy Gowda (3915) | answered Feb 12 '18, 10:48 p.m.

What is the value of name and value you see in the script? You could print the variable and attribute values using _sessionLogger. The values are printed in the console. Additionally, you could test the script without having to generate document.



Thanks,
Kumar


Comments
Shannon Struttmann commented Feb 13 '18, 9:17 a.m.

That's the weird thing, every variation works fine with the test script button, but not when I print the document..


permanent link
Kumaraswamy Gowda (3915) | answered Feb 13 '18, 9:23 a.m.

You might have to check "XHTML input/output" check boxes in the script expression dialog.


Comments
Shannon Struttmann commented Feb 13 '18, 9:44 a.m.

I think I see the problem. Using the session logger, I see now that if my "ReqProID" attribute is blank in DNG, it doesn't even consider it to exist, so it won't even be able to check for a 'value'. Looks like I need another layer of logic. I'll be back if I can't figure it out.
Thanks for the help


permanent link
Subramanya Prasad Pilar (3.9k14) | answered Feb 13 '18, 1:53 p.m.

You can think of more than solution for this. One simple way is to store all name & values in a variable (_headersMap) and then print ReqProID value if exists or else print the identifier. You can try this Script Expression:
var sepPos=_headersMap.indexOf("|;");
var reqPos=_headersMap.indexOf("ReqProID");
if (reqPos == -1){
_headersMap.substring(0,sepPos);}
else{
_headersMap.substring(reqPos+9, _headersMap.indexOf("|;",reqPos));}

Please refer the screenshot of sample template:


Your answer


Register or to post your answer.