Highlighted
Honored Contributor.
Honored Contributor.
557 views

Adding SRC User Selections to html templates for requestTask

I was able to add user selections into the html templates for requests by adding the below language to the expressions, but when I try this same language in a email from a requestTask, the variables do not display. I don't see anything specific to the file so I'm not sure what I'm missing. 

//Get User Selections

 

var userOptionfle= new SCFile('userOption');

var firstname="firstname";

var middlename="middlename";

var lastname = "lastname";

var iRet1 = userOptionfle.doSelect('Ticket.ID="' + $RECORD.number + '" and Option.Name="' + firstname + '"');

if (iRet1 == RC_SUCCESS)

   {

   var htmlfirst=userOptionfle.Option_Value[0];

   }

var iRet1 = userOptionfle.doSelect('Ticket.ID="' + $RECORD.number + '" and Option.Name="' + middlename + '"');

if (iRet1 == RC_SUCCESS)

   {

   var htmlmiddle=userOptionfle.Option_Value[0];

   }

var iRet1 = userOptionfle.doSelect('Ticket.ID="' + $RECORD.number + '" and Option.Name="' + lastname + '"');

if (iRet1 == RC_SUCCESS)

   {

   var htmllast=userOptionfle.Option_Value[0];

   }  

0 Likes
11 Replies
Highlighted
Micro Focus Frequent Contributor
Micro Focus Frequent Contributor

Re: Adding SRC User Selections to html templates for requestTask

Could you please unload the htmltemplates records which works and which does not work, and add them as attachment for reference?

0 Likes
Highlighted
Micro Focus Frequent Contributor
Micro Focus Frequent Contributor

Re: Adding SRC User Selections to html templates for requestTask

After investigation on an OOTB environment, I think I understand the background of your issue.

1. A catalog item "Interface Type" could set to "Open New Request", User Selections could be defined, for example firstname, middlename and lastname.
2. When ordering such a catalog item, a new Interaction ticket is open and link to a new Request Fulfillment ticket.
3. The Request Fulfillment ticket would linked to userOption records.
Note: the userOption records linked to Request Fulfillment tickets, do not linked to Request Task.
So your codes works for request tickets, does not work for requestTask tickets
4. Request Task could be open and linked to Request Fulfillment ticket.


In ordert to get your code working, your need to use the requestTask field parent.request, not the field number
Change "$RECORD.number" to "$RECORD.parent_request".

Hope above information helps.

0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: Adding SRC User Selections to html templates for requestTask

 and i have no such table "UserOption" (sm 9.3)

0 Likes
Highlighted
Micro Focus Frequent Contributor
Micro Focus Frequent Contributor

Re: Adding SRC User Selections to html templates for requestTask

I just verified on SM app 9.35.0012 classic, there is no userOption table, there is "Request Management" moduel which ticket is started with Q, not "Request Fulfillment" module witch ticket is started with RF in later SM codeless version. 

As there is no userOption table in SM9.3 of your env, above function could not be used.

0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: Adding SRC User Selections to html templates for requestTask

I believe table userOptions was introduced in version 9.40. If it's not available, Plan B is to use svc.options field (XML) and loop XML table through to pick values into HTML template.

I don't have versions later than SM 9.41 in my hands, but I assume a following example works in many environments.

It requires xml as an attribute (such as svc.options) and converts it into a HTML page.

// svc.options to HTML converting, author @Kelalek2
function UserSelections( xml ) { // CSS styling var style = "<STYLE>\ body{\COLOR: #000000;\ FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;\ BACKGROUND-COLOR: #ffffff;\ HEIGHT: 70%;\ }\ #styletable{\ VERTICAL-ALIGN: top;\ TOP: 10px;\ POSITION: absolute;\ WIDTH: 80%;\ LEFT: 10%;\ FONT-SIZE: 12px;\ FONT-FAMILY: Helvetica, sans-serif;\ opacity: 0.7;\ filter:alpha(opacity=70);\ }\ \</STYLE>"; var ROWBG0 = "#f8f9f9"; var ROWBG1 = "#cddaf3"; // XML preparation var xmlString;var xmlObject = new XML(); xmlString = xml; if ( !xmlObject.setContent( xmlString ) ) { return false; } // HTML formatting, tables used var updates = new Array(); var updates_string="<html><head>"; updates_string+=style+"</head><body>"; updates_string+="<table id='styletable' cellpadding='8'>"; var bgcolor=""; var count=0; var parent = xmlObject.getParentNode(); var form = parent.getFirstChildElement(); var node = form.getFirstChildElement(); var rows = 0; while ( node != null ) { var label = node.getAttributeValue("label"); var value = node.getValue(); // HTML tag sanitation value = value.replace(/</g, "&lt;"); value = value.replace(/>/g, "&gt;"); // convert row change into a forced line break value = value.replace(/\n/g, "</br>"); // odd and even rows have a different bgcolor bgcolor=eval('bgcolor=ROWBG'+(count%2)) var style= "style='background:"+bgcolor+"; width:150px;'"; if (value!=null) updates_string+="<tr "+style+"><td width='50%' text-align='left'><b>"+label+"</b></td><td text-align='right'>" + value+"</td></tr>"; count++; node = node.getNextSiblingElement(); } // Closing table & HTML updates_string=updates_string+"</table></body></html>"; return updates_string; }

I removed some proprietary parts I'm not allowed to share, but it should we a working-ish as an example to play with.

---
Moving on, this account is no longer active. Best regards, Kelalek
- So Long, and Thanks for All the Fish
0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: Adding SRC User Selections to html templates for requestTask

Where and how do you use this result ?

return updates_string;

 

0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: Adding SRC User Selections to html templates for requestTask

Use case for that code was to convert ugly looking svc.options to more readable format. As you can see, the code produces a HTML page.

I have a HTML viewer component that calls the code. To be precise, in fact call is made to a wrapper function that checks if svc.options exists and if it is, passes xml to the code I posted. And of course returns the result back to HTML viewer.

(In fact a variable "updates_string"  and the CSS code is just a leftover from the code, that converted ugly looking Activity Updates into a readable format.)

---
Moving on, this account is no longer active. Best regards, Kelalek
- So Long, and Thanks for All the Fish
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: Adding SRC User Selections to html templates for requestTask

So, you use it in FormDesigner in HTML viewer component

and in properties in field "HTML generation script" you set call of this function ?

0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: Adding SRC User Selections to html templates for requestTask

Exactly.

Another possibility is to add a variable (like $htmlcontent) into HTML viewer's input, and make a call to the function I provided in the ruleset. Such as

system.vars.$htmlcontent=system.library.YourLibName.YourFunctionName( record.svc_options );

Put the ruleset to "On Display" state in the workflow and it should be fine.

EDIT: Please note that rendering XML to HTML may slow down ticket's total rendering time a bit, but what I've experienced, the difference is not noticeable. If you convert activities into HTML, depending on number of updates, script's slowdown effect is more noticeable.

Based on user feedback, there's no return to old 1990's style of formatting.

 

---
Moving on, this account is no longer active. Best regards, Kelalek
- So Long, and Thanks for All the Fish
0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: Adding SRC User Selections to html templates for requestTask

Your script put in html list instead of list.label (for dropdown list, flag checkbox,...)

=

About second method

We have no Process designer, so need put call of sript to calculate $htmlcontent in Format Control .

=

0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: Adding SRC User Selections to html templates for requestTask

Like I said in one of my posts, the code was offered as "something to play with example" of how to go through the XML tree. I removed some parts I'm not allowed to share. The feature you missed was one of those.

Therefore I invite also others to publish the forks they've done. Not too many guys publish their code here...

---
Moving on, this account is no longer active. Best regards, Kelalek
- So Long, and Thanks for All the Fish
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.