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];


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

  • 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.

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

  • 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.

  • 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.

  • Where and how do you use this result ?

    return updates_string;


  • 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.)

  • So, you use it in FormDesigner in HTML viewer component

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

  • 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.


  • 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 .