Get the display value in service portal widget for reference fields

Thanvik1
Tera Contributor

Once request item get created, in service portal widget customer view couple of variable values showing in sys id format instead of actual value (display values).This is happen after Rome upgrade. Here i am giving the widget code. 

HTML:

<div ng-if="data.canRead" class="panel b">
<div class="panel-heading bg-primary">
<div ng-init="spSearch.targetRequests()">
<sp-c-link target="form" table="data.table" id="data.sys_id"/>
</div>
<span ng-if="data.agent" >
${Agent working on this {{data.tableLabel}}}:
<div>{{data.agent}}</div>
</span>
<span ng-if="!data.agent && data.agentPossible" >${Your request has been submitted}</span>
<span ng-if="!data.agentPossible">${{{data.tableLabel}} record details}</span>
</div>

<div class="panel-body">
<div ng-if="data.fields.length > 0">
<div class="row">
<div class="col-md-6 col-sm-12 col-xs-6 m-b break-word" ng-repeat="field in data.fields"
ng-if="field.value && (field.type != 'decimal' || field.type == 'decimal' && field.value != 0)" >
<label class="m-n">{{field.label}}</label>
<span ng-switch="field.type">
<div ng-switch-when="glide_date_time" title="{{field.display_value}}">
<sn-time-ago timestamp="::field.value" />
</div>
<div ng-switch-default >{{field.display_value}}</div>
</span>
</div>
</div>
</div>

<div ng-if="data.variables.length > 0" ng-init="variable_toggle=true">
<h4 ng-click="variable_toggle = !variable_toggle" style="cursor: pointer;">
<span style="font-size: 12px;" class="glyphicon"
ng-class="{'glyphicon-chevron-down': !variable_toggle, 'glyphicon-chevron-up': variable_toggle}"></span>
${Options}
</h4>

<div ng-if="variable_toggle">
<hr>
<div class="m-b break-word" ng-repeat="variable in data.variables">
<label class="m-n">{{variable.label}}</label>
<div>{{variable.display_value}}</div>
</div>
</div>
</div>
</div>

<div ng-if="data.agentPossible && !data.agent && options.pickup_msg" class="panel-footer">
<div id="ticket_fields_footer" class="text-center text-muted" style="font-style: italic;" ng-bind-html="data.pickupMsg">
</div>
</div>

</div>

Client Code:

function ($scope, spUtil) {
$scope.$on('record.updated', function(name, data) {
spUtil.update($scope);
})
}

Server Script:

(function(){
data.pickupMsg = gs.getMessage(options.pickup_msg);
var gr = $sp.getRecord();
data.canRead = gr.canRead();
if (!data.canRead)
return;

var agent = "";
var a = $sp.getField(gr, 'assigned_to');
if (a != null)
agent = a.display_value;

var fields = $sp.getFields(gr, 'number,state,sys_created_on,stage');
if (gr.getValue("sys_mod_count") > 0)
fields.push($sp.getField(gr, 'sys_updated_on'));

if (gr.getValue('price') > 0)
fields.push($sp.getField(gr, 'price'));

if (gr.getValue('recurring_price') > 0) {
var rp = $sp.getField(gr, 'recurring_price');
if (gr.isValidField("recurring_price"))
rp.display_value = rp.display_value + " " + gr.getDisplayValue("recurring_frequency");
fields.push(rp);
}

data.tableLabel = gr.getLabel();
data.fields = fields;
data.variables = $sp.getVariablesArray();
data.agent = agent;
data.agentPossible = gr.isValidField("assigned_to");
data.table = gr.getTableName();
data.sys_id = gr.getUniqueValue();
})()

form the above widget script where we need the update to fix the issue. 

6 REPLIES 6

Thanks for the update Ankuar!

I have updated the getDisplayValue() for Business Service in recordproducer script. This time Business Service is working fine but Serviceoffering shows with sysid. If we apply getDisplayValue for both fields then also it perform the same. If we donot add get display value in RITM form it shows the above screenshot formatt (BS-with sysid, SO-with value).other senario add the getDisplyValue to only to BS or both BS and SO: BS is showing the value ,SO-showing the sysid. 

SO is the dependent field on BS (like category and SubCategory).

Record Producer script:

// current and producer fields.
var atr=new x_ibmip_tktrouting.advancedTicketRouting();
var recordType = atr.getRecordTypeToGenerate(producer.business_service,
producer.service_offering,
producer.category,
producer.subcategory,
'incident' /* default return */
);
//gs.log('--dq in record producer; sys_id ='+current.sys_id.toString());
var incsysid = current.sys_id.toString();
if(recordType=='sc_req_item') {
var doritm=new IBMRITMUtil();
var vars=doritm.getVarTemplate();
vars.Vars.src_requested_by = producer.src_reported_by;
vars.Vars.src_requested_for = producer.src_affected_person;
vars.Vars.src_best_contact_number = producer.src_phone_number;
vars.Vars.src_best_contact_method =
doritm.capitalizeFirst(producer.src_contact_type.toString());
vars.Vars.src_site_req_for = producer.src_loc_code;



if (producer.src_affected_person.sys_id.toString() == '5136503cc611227c0183e96598c4f706') {
vars.Vars.src_external_user_name = producer.src_inc_external_user_name;
vars.Vars.src_external_user_email = producer.src_inc_external_user_email;
vars.Vars.src_external_user_location = producer.src_inc_external_user_location;
}

vars.Vars.src_cmdb_ci = producer.cmdb_ci;
vars.Vars.src_business_service = producer.business_service.getDisplayValue();
vars.Vars.src_service_offering = producer.service_offering;
vars.Vars.u_controlled_information_level_1 = producer.u_controlled_information_level_1;
//gs.log('lee' + producer.u_controlled_information_level_1);
vars.Vars.src_category = producer.category;
vars.Vars.src_subcategory = producer.subcategory;
vars.Vars.src_short_description_en = producer.src_short_description_en;
vars.Vars.src_description_en = producer.src_description_en;
vars.Vars.src_comments_details = producer.src_comments_details;
vars.Vars.impact = producer.impact;
vars.Vars.urgency = producer.urgency;

// vars.Vars.src_common_short_desc_1 = producer.business_service.getDisplayValue() + " / " + producer.service_offering.getDisplayValue();
// vars.Vars.src_common_short_desc_2 = producer.category.getDisplayValue() + " / " + producer.subcategory.getDisplayValue();
// vars.Vars.src_common_short_desc_1 = producer.src_short_description_en;

var ritm=doritm.orderItem('Request a Service',vars);
current.setAbortAction(true);
current.sys_id = ritm.sys_id.toString();
current.number = ritm.number.toString();
current.sys_class_name = 'sc_request';
//move attachments to ritm
var ri=new GlideRecord('sc_req_item');
ri.addQuery('request',ritm.sys_id.toString());
//gs.log(ri.getEncodedQuery());
ri.query();
if(ri.next()) {
//to=parm1
//from=parm2
if(producer.business_service=="b14cbb3edb53b6802c117bedae9619f1" && ((producer.category=="issue" && producer.subcategory=="projectWise_issue") ||(producer.category=="request" && producer.subcategory=="projectwise_request")))
{
if(producer.src_loc_code.u_geography=='APAC')
ri.assignment_group=gs.getProperty('ProjectWise APAC'); //ProjectWise APAC
if(producer.src_loc_code.u_geography=='EMEA')
ri.assignment_group=gs.getProperty('ProjectWise EMEA'); //ProjectWise EMEA
}
ri.update();
gs.eventQueue('rp.move.attachment.to.ritm',ri,ri.sys_id.toString(),incsysid);
}
producer.redirect = "sc_request.do?sys_id="+ritm.sys_id.toString();
} else {
current.caller_id = producer.src_affected_person;
current.u_raised_by = producer.src_reported_by;
current.contact_type = 'self-service';
current.cmdb_ci = producer.cmdb_ci;
current.u_contact_number = producer.src_phone_number;
if (producer.src_affected_person.sys_id.toString() == '5136503cc611227c0183e96598c4f706') {
current.u_external_user_name = producer.src_inc_external_user_name;
current.u_external_user_email = producer.src_inc_external_user_email;
current.u_external_user_location = producer.src_inc_external_user_location;
}
// current.short_description = 'Self Service - ';
current.short_description += producer.src_short_description_en;
current.location = producer.src_loc_code;
// make notes from the rest?
var notes = "Description: " + producer.src_description_en;
current.description = notes;
if(producer.business_service=="b14cbb3edb53b6802c117bedae9619f1" && ((producer.category=="issue" && producer.subcategory=="projectWise_issue") ||(producer.category=="request" && producer.subcategory=="projectwise_request")))
{
if(producer.src_loc_code.u_geography=='APAC')
current.assignment_group=gs.getProperty('ProjectWise APAC'); //ProjectWise APAC
if(producer.src_loc_code.u_geography=='EMEA')
current.assignment_group=gs.getProperty('ProjectWise EMEA'); //ProjectWise EMEA
}

//STRY0003017 Updating the Assignment group to I-ACM-SD-AP-CN if the user belogs to below locations
if(producer.src_affected_person.country.match(/^(CN|HK|TW|KH|TA)$/) ){
current.assignment_group = 'e3faec1cdbcab6004620d2c75e961948'; //I-ACM-SD-AP-CN
}
}

 

 

Hi,

what are you doing with above script?

How does it relate to the variables being displayed on portal?

the above script you shared is for record producer script and has no direct relation with widget script

Did you check the business service populated has the display value field populated or not?

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader