Multirow variable set value shows empty after submit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2019 01:46 PM
Hi,
We've a catalog item available for end-user over Service Portal. After all the approvals, catalog items gets created. This catalog item is contains a mult-row variable set.
The value of the multirow variable set is showing as empty in log messages.
What could be the cause?
Thanks.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2019 02:57 PM
Look at the answer on very close question. Probably you have the same problem. If not then you should describe the problem more detailed so that one will be able to reproduce it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2019 06:09 AM
Yes, that's a very close question.
Multi-row variable set values are intact while I request item from console but not on service portal. Issue persists even after setting the on change client script as inactive.
Widget is customized in such a way that Once the catalog item is submitted, REQ number is shown in a modal dialog box instead of redirecting as defined in OOB.
We've a custom catalog item widget cloned from SC Catalog Item Deprecated.
Server Script:
// populate the 'data' variable with catalog item, variables, and variable view
(function() {
/*
// portal can specify a catalog and catalog category home page
data.sc_catalog_page = $sp.getDisplayValue("sc_catalog_page") || "sc_home";
data.sc_category_page = $sp.getDisplayValue("sc_category_page") || "sc_category";
options.show_add_cart_button = (options.show_add_cart_button == "true");
if (options.page) {
var pageGR = new GlideRecord("sp_page");
options.page = (pageGR.get(options.page)) ? pageGR.getValue("id") : null;
}
if (options.table) {
var tableGR = new GlideRecord("sys_db_object");
options.table = (tableGR.get(options.table)) ? tableGR.getValue("name") : null;
}
options.url = options.url || "?id={page}&table={table}&sys_id={sys_id}";
data.showPrices = $sp.showCatalogPrices();
var m = data.msgs = {};
m.serviceCatalogMsg = gs.getMessage("Service Catalog");
m.submitMsg = gs.getMessage("Submit");
m.submittedMsg = gs.getMessage("Submitted");
m.createdMsg = gs.getMessage("Created");
m.trackMsg = gs.getMessage("track using 'Requests' in the header or");
m.clickMsg = gs.getMessage("click here to view");
m.dialogTitle = gs.getMessage("Delete Attachment");
m.dialogMessage = gs.getMessage("Are you sure?");
m.dialogOK = gs.getMessage("OK");
m.dialogCancel = gs.getMessage("Cancel");
data.maxAttachmentSize = parseInt(gs.getProperty("com.glide.attachment.max_size", 1024));
if (isNaN(data.maxAttachmentSize))
data.maxAttachmentSize = 24;
m.largeAttachmentMsg = gs.getMessage("Attached files must be smaller than {0} MB - please try again", "" + data.maxAttachmentSize);
m.renameSuccessMsg = gs.getMessage("Attachment renamed successfully");
m.deleteSuccessMsg = gs.getMessage("Attachment deleted successfully");
if (input)
data.sys_id = input.sys_id;
else if (options.sys_id)
data.sys_id = options.sys_id;
else
data.sys_id = $sp.getParameter("sys_id") || $sp.getParameter('sl_sys_id');
if (!data.sys_id)
return;
data._attachmentGUID = gs.generateGUID();
var validatedItem = new sn_sc.CatItem('' + data.sys_id);
if (!validatedItem.canView() || !validatedItem.isVisibleServicePortal())
return;
data.sc_cat_item = $sp.getCatalogItem(data.sys_id, true);
if (data.sc_cat_item.category) {
var categoryJS = new sn_sc.CatCategory(data.sc_cat_item.category);
data.category = {
name: categoryJS.getTitle(),
url: '?id='+data.sc_category_page+'&sys_id=' + data.sc_cat_item.category
}
data.categories = [];
data.categories.push({
label: categoryJS.getTitle(),
url: '?id='+data.sc_category_page+'&sys_id=' + data.sc_cat_item.category
});
while(categoryJS && categoryJS.getParent()) {
var parentId = categoryJS.getParent();
categoryJS = new sn_sc.CatCategory(parentId);
var category = {
label: categoryJS.getTitle(),
url: '?id='+data.sc_category_page+'&sys_id=' + parentId
};
data.categories.unshift(category);
}
}
$sp.logStat('Catalog View', data.sc_cat_item.sys_class_name, data.sys_id, data.sc_cat_item.name);
data.msgs.delete_attachment = gs.getMessage("Delete Attachment?"); //commented
*/
data.sc_catalog_page = $sp.getDisplayValue("sc_catalog_page") || "sc_home";
data.sc_category_page = $sp.getDisplayValue("sc_category_page") || "sc_category";
options.show_add_cart_button = (options.show_add_cart_button == "true");
if (options.page) {
var pageGR = new GlideRecord("sp_page");
options.page = (pageGR.get(options.page)) ? pageGR.getValue("id") : null;
}
if (options.table) {
var tableGR = new GlideRecord("sys_db_object");
options.table = (tableGR.get(options.table)) ? tableGR.getValue("name") : null;
}
options.url = options.url || "?id={page}&table={table}&sys_id={sys_id}";
data.showPrices = $sp.showCatalogPrices();
var m = data.msgs = {};
m.serviceCatalogMsg = gs.getMessage("Service Catalog");
m.submitMsg = gs.getMessage("Submit");
m.submittedMsg = gs.getMessage("Submitted");
m.createdMsg = gs.getMessage("Created");
m.trackMsg = gs.getMessage("track using 'Requests' in the header or");
m.clickMsg = gs.getMessage("click here to view");
m.dialogTitle = gs.getMessage("Delete Attachment");
m.dialogMessage = gs.getMessage("Are you sure?");
m.dialogOK = gs.getMessage("OK");
m.dialogCancel = gs.getMessage("Cancel");
data.maxAttachmentSize = parseInt(gs.getProperty("com.glide.attachment.max_size", 1024));
if (isNaN(data.maxAttachmentSize))
data.maxAttachmentSize = 24;
m.largeAttachmentMsg = gs.getMessage("Attached files must be smaller than {0} MB - please try again", "" + data.maxAttachmentSize);
m.renameSuccessMsg = gs.getMessage("Attachment renamed successfully");
m.deleteSuccessMsg = gs.getMessage("Attachment deleted successfully");
if (input)
data.sys_id = input.sys_id;
else if (options.sys_id)
data.sys_id = options.sys_id;
else
data.sys_id = $sp.getParameter("sys_id") || $sp.getParameter('sl_sys_id');
if (!data.sys_id)
return;
data._attachmentGUID = gs.generateGUID();
var validatedItem = new sn_sc.CatItem('' + data.sys_id);
if (!validatedItem.canView() || !validatedItem.isVisibleServicePortal())
return;
data.sc_cat_item = $sp.getCatalogItem(data.sys_id, true);
data.sc_cat_item.view = "sp";
if (data.sc_cat_item.category) {
var categoryJS = new sn_sc.CatCategory(data.sc_cat_item.category);
data.category = {
name: categoryJS.getTitle(),
url: '?id='+data.sc_category_page+'&sys_id=' + data.sc_cat_item.category
}
data.categories = [];
data.categories.push({
label: categoryJS.getTitle(),
url: '?id='+data.sc_category_page+'&sys_id=' + data.sc_cat_item.category
});
while(categoryJS && categoryJS.getParent()) {
var parentId = categoryJS.getParent();
categoryJS = new sn_sc.CatCategory(parentId);
var category = {
label: categoryJS.getTitle(),
url: '?id='+data.sc_category_page+'&sys_id=' + parentId
};
data.categories.unshift(category);
}
}
$sp.logStat('Catalog View', data.sc_cat_item.sys_class_name, data.sys_id, data.sc_cat_item.name);
})()
Client Script:
function ($scope,$uibModal, $http, spUtil, nowAttachmentHandler, $rootScope, $sanitize, $window, $sce, i18n, $timeout, $log, spAriaUtil, $location, spModal) {
var c = this;
c.quantity = 1;
if ($scope.data.sc_cat_item)
$scope.data.sc_cat_item.description = $sce.trustAsHtml($scope.data.sc_cat_item.description);
c.widget._debugContextMenu = [
[ i18n.getMessage("Open") + " sc_cat_item", function(){
var item = c.data.sc_cat_item;
$window.open("/sp_config?id=form&table=" + item.table + "&sys_id=" + item.sys_id); }]
];
c.showAddCartBtn = function() {
return c.options.show_add_cart_button &&
c.data.sc_cat_item.sys_class_name !== "sc_cat_item_producer" &&
!c.data.sc_cat_item.no_cart;
}
c.showQuantitySelector = function() {
return c.data.sc_cat_item.sys_class_name !== "sc_cat_item_producer" &&
!c.data.sc_cat_item.no_quantity &&
(!c.data.sc_cat_item.no_order_now || !c.data.sc_cat_item.no_cart);
}
c.showOrderNowButton = function() {
return c.data.sc_cat_item.use_sc_layout || !c.data.sc_cat_item.no_order_now;
}
c.allowOrder = function() {
if (c.data.sc_cat_item.use_sc_layout)
return true;
if (c.data.sc_cat_item.no_order)
return false;
if (c.data.sc_cat_item.no_order_now && c.data.sc_cat_item.no_cart)
return false;
return true;
}
$scope.$on('dialog.upload_too_large.show', function(e){
$log.error($scope.m.largeAttachmentMsg);
spUtil.addErrorMessage($scope.m.largeAttachmentMsg);
});
$scope.m = $scope.data.msgs;
$scope.submitButtonMsg = $scope.m.submitMsg;
var ah = $scope.attachmentHandler = new nowAttachmentHandler(setAttachments, appendError);
function appendError(error) {
spUtil.addErrorMessage(error.msg + error.fileName);
}
ah.setParams('sp_portal', $scope.data._attachmentGUID, 1024 * 1024 * $scope.data.maxAttachmentSize);
function setAttachments(attachments, action) {
$scope.attachments = attachments;
if (action === "added")
$scope.setFocusToAttachment();
if (action === "renamed")
spAriaUtil.sendLiveMessage($scope.m.renameSuccessMsg);
if (action === "deleted")
spAriaUtil.sendLiveMessage($scope.m.deleteSuccessMsg);
}
$scope.attachmentHandler.getAttachmentList();
$scope.confirmDeleteAttachment = function(attachment) {
spModal.confirm($scope.data.msgs.delete_attachment).then(function() {
$scope.attachmentHandler.deleteAttachment(attachment);
$('#add_attachment_button').focus();
});
}
// Breadcrumbs
if ($scope.data.sc_cat_item) {
if (!$scope.data.categories)
$scope.data.categories = [];
$scope.data.categories.unshift({label: $scope.data.msgs.serviceCatalogMsg, url: '?id=' + $scope.data.sc_catalog_page});
$scope.data.categories.push({label: $scope.data.sc_cat_item.name, url: '#'});
$timeout(function() {
$scope.$emit('sp.update.breadcrumbs', $scope.data.categories);
});
spUtil.setSearchPage('sc');
} else {
var notFoundBC = [{label: $scope.data.msgs.serviceCatalogMsg, url: '?id=' + $scope.data.sc_catalog_page}];
$timeout(function() {
$scope.$emit('sp.update.breadcrumbs', notFoundBC);
});
spUtil.setSearchPage('sc');
}
c.getItemId = function () {
return $scope.data.sc_cat_item ? $scope.data.sc_cat_item.sys_id : -1;
};
var g_form;
$scope.$on('spModel.gForm.initialized', function(e, gFormInstance){
if (gFormInstance.getSysId() != -1 && gFormInstance.getSysId() != c.getItemId())
return;
g_form = gFormInstance;
// This runs after all onSubmit scripts have executed
g_form.$private.events.on('submitted', function(){
if ($scope.data.sc_cat_item.item_action === "order")
getOne();
else if ($scope.data.sc_cat_item.item_action === "add_to_cart")
addToCart();
});
});
$scope.triggerAddToCart = function() {
$scope.data.sc_cat_item.item_action = "add_to_cart";
$scope.data.sc_cat_item.quantity = c.quantity;
if (g_form)
g_form.submit();
}
$scope.triggerOnSubmit = function(){
$scope.data.sc_cat_item.item_action = "order";
$scope.data.sc_cat_item.quantity = c.quantity;
if (g_form)
g_form.submit();
}
// order / create request
function getOne() {
postCatalogFormRequest().success(function(response) {
var a = response.result ? response.result : response.answer;
var n = a.number;
$scope.$emit("$$uiNotification", response.$$uiNotification ? response.$$uiNotification : a.$$uiNotification);
$scope.$emit("$sp.sc_cat_item.submitted", a);
if (n)
issueMessage(n, a.table, a.sys_id, a.redirect_to, a.redirect_portal_url);
$scope.submitting = false;
$scope.submitButtonMsg = $scope.m.submittedMsg;
}).error(function(response) {
console.log(response);
});
}
function addToCart() {
postCatalogFormRequest().success(function(response) {
$rootScope.$broadcast("$sp.service_catalog.cart.add_item");
$rootScope.$broadcast("$sp.service_catalog.cart.update");
//spUtil.addInfoMessage("Added item to shopping cart");
$scope.submitting = false;
c.status = "Added item to shopping cart";
});
}
function postCatalogFormRequest() {
setFieldsReadonly();
$scope.submitted = true;
$scope.submitting = true;
var requestUrl;
var reqData = {};
if ($scope.data.sc_cat_item.sys_class_name === "sc_cat_item_producer") {
requestUrl = '/api/sn_sc/v1/servicecatalog/items/' + $scope.data.sc_cat_item.sys_id + '/submit_producer';
for(var obj in $scope.data.sc_cat_item._fields)
reqData[$scope.data.sc_cat_item._fields[obj].name] = $scope.data.sc_cat_item._fields[obj].value;
reqData = {'variables' : reqData, 'attachment_id' : $scope.data._attachmentGUID, 'attachment_table': 'sp_portal', 'get_portal_messages': 'true'};
}
else {
requestUrl = spUtil.getURL('sc_cat_item');
reqData = $scope.data.sc_cat_item;
reqData._attachmentGUID = $scope.data._attachmentGUID;
}
return $http.post(requestUrl, reqData);
}
// spModel populates mandatory - hasMandatory is called by the submit button
$scope.hasMandatory = function(mandatory) {
return mandatory && mandatory.length > 0;
};
// switch catalog items
var unregister = $scope.$on('$sp.list.click', onListClick);
$scope.$on("$destroy", function() {
unregister();
});
function onListClick(evt, arg) {
$scope.data.sys_id = arg.sys_id;
spUtil.update($scope);
}
function setFieldsReadonly(){
var allFields = g_form.getFieldNames();
for(var fieldName in allFields){
g_form.setReadOnly(allFields[fieldName], true);
}
}
//comented 27/12/2018
/*
function issueMessage(n, table, sys_id, redirectTo, redirectUrl) {
var page = table == 'sc_request' ? 'sc_request' : 'ticket';
if (c.options.page) {page = c.options.page;}
if (c.options.table) {table = c.options.table;}
if (redirectTo == 'catalog_home') page = 'sc_home';
var url = spUtil.format(c.options.url, {page: page, table: table, sys_id: sys_id});
if (c.options.auto_redirect == "true") {
$timeout(function() {
if (redirectUrl)
$location.url(redirectUrl);
else
$location.url(url);
}, 1000);
return;
}
var page1 = table == 'sc_request' ? 'sc_request' : 'ticket';
if (c.options.page) {page = c.options.page;}
if (c.options.table) {table = c.options.table;}
if (redirectTo == 'catalog_home') page = 'sc_home';
var url1 = spUtil.format(c.options.url, {page: page, table: table, sys_id: sys_id});
recordURL = url;
var head = ""; var t1 = ""; var secondHead = "";
if(table == "sc_request"){
head = "Your Request was successfully submitted.";
t = "Track your Request: ";
}
var t = $scope.m.createdMsg + " " + n + " - ";
t += $scope.m.trackMsg;
t += ' <a href="' + url + '">' + $scope.m.clickMsg + '</a>';
spUtil.addInfoMessage(t);
}
*/
function issueMessage(n, table, sys_id, redirectTo, redirectUrl) {
c.modalInstance = $uibModal.open({
templateUrl: 'modalTemplate',
scope: $scope
});
var page = table == 'sc_request' ? 'sc_request' : 'ticket';
if (c.options.page) {page = c.options.page;}
if (c.options.table) {table = c.options.table;}
if (redirectTo == 'catalog_home') page = 'sc_home';
var url = spUtil.format(c.options.url, {page: page, table: table, sys_id: sys_id});
recordURL = url;
var head = ""; var t = ""; var secondHead = "";
if(table == "sc_request"){
head = "Your Request was successfully submitted.";
t = "Track your Request: ";
}else if(table == "incident"){
var cltype = g_form.getValue('u_classification_type');
//alert("Classification type " +cltype);
var catValue = g_form.getValue('subcategory');
if(catValue == "Only Single Event" || catValue == "Punched but Absent"){
secondHead = "Your ticket has been assigned to Security Specialist";
}
else if(cltype == 'Facility - iViva' || cltype == 'Facility - eFacility'){
secondHead = "Your ticket has been assigned to Facility Team";
}
else{
secondHead = "Your ticket has been assigned to IT Specialist";
}
head = "Your Issue was successfully submitted.";
t = "Track your issue: ";
}
t += '<a href="' + url + '">' + n + '</a>';
c.head = head;
c.secondHead = secondHead;
c.modal = $sce.trustAsHtml(t);
}
}
HTML Template:
<!--addedd-->
<div id="sc_cat_item" >
<div class="row" ng-if="::data.sc_cat_item" >
<div ng-if="::data.sc_cat_item.picture" class="col-sm-3">
<div class="panel panel-{{::options.color}} b wrapper-lg text-center">
<img class="img-responsive catalog-item-image" alt="{{::data.sc_cat_item.name}}" style="display: inline" ng-src="{{::data.sc_cat_item.picture}}" />
</div>
</div>
<div ng-class="{true:'col-sm-9',false:'col-sm-12'}[data.sc_cat_item.picture.length > 0]">
<div class="panel panel-default">
<div class="wrapper-md">
<h1 class="h2 m-t-none m-b-sm font-thin">{{::data.sc_cat_item.name}}</h1>
<div class="text-muted">{{::data.sc_cat_item.short_description}}</div>
</div>
<div ng-if="::data.sc_cat_item.description" class="wrapper-md b-t">
<div ng-bind-html="::data.sc_cat_item.description"></div>
</div>
<div ng-if="::data.sc_cat_item.content_type == 'external'" class="wrapper-md"><a ng-href="{{::data.sc_cat_item.url}}" target={{::data.sc_cat_item.target}}>{{::data.sc_cat_item.url}} ➚</a></div>
<div ng-if="::data.sc_cat_item.content_type == 'kb'" class="wrapper-md"><a ng-href="?id=kb_article&sys_id={{::data.sc_cat_item.kb_article}}">${Go to KB Article:} {{::data.sc_cat_item.kb_article_description}}</a></div>
<div ng-if="::data.sc_cat_item._fields">
<sp-cat-item item="::data.sc_cat_item" />
<form>
<div ng-class="{'b-t wrapper-md': data.sc_cat_item._view.length}">
<!-- display view and model -->
<!--addedd --> <sp-model form-model="::data.sc_cat_item" mandatory="mandatory"></sp-model>
</div>
</form>
<div ng-if="data.sc_cat_item.sys_class_name != 'sc_cat_item_content'" class="b-t wrapper-md">
<div class="m-b" ng-if="data.showPrices && (data.sc_cat_item.price || data.sc_cat_item.recurring_price)" >
<div ng-if="data.sc_cat_item.price" class="h4 cat_item_price">${Price}: {{data.sc_cat_item.price}}</div>
<em ng-if="data.sc_cat_item.recurring_price" class="cat_item_price">${Recurring Price}: {{data.sc_cat_item.recurring_price + ' ' + data.sc_cat_item.recurring_price_frequency}}</em>
</div>
<now-attachments-list template="sp_attachment_single_line" ></now-attachments-list>
<span ng-if="::c.allowOrder()">
<!-- <select ng-if="c.showQuantitySelector()"
ng-disabled="submitted"
class="form-control quantity-selector"
ng-model="c.quantity"
aria-label="${Quantity}"
ng-options="num for num in [1,2,3,4,5,6,7,8,9,10]">
--> </select>
<label ng-if="!submitted" style="float:right;font-weight:normal;cursor:pointer;"><sp-attachment-button></sp-attachment-button><span style="padding-left:4px;">${Add attachments}</span></label>
<button ng-if="::c.showOrderNowButton()" tabindex="0" name="submit" ng-disabled="submitted" ng-click="triggerOnSubmit()" class="btn btn-primary">{{submitButtonMsg}}</button>
<button tabindex="0" ng-if="c.showAddCartBtn()" name="submit" ng-disabled="submitted" ng-click="triggerAddToCart()" class="btn btn-default">${Add to Cart}</button>
<span ng-if="submitting" style="padding-left:4px">${Submitting...}</span>
</span>
<div ng-if="hasMandatory(mandatory)" class="alert alert-info" style="margin-top: .5em">
<span ng-if="hasMandatory(mandatory)">${Required information} </span>
<span ng-repeat="f in mandatory" class="label label-danger" style="margin-right: .5em; display: inline-block;">{{::f.label}}</span>
</div>
</div>
</div>
</div>
</div>
</div>
<div ng-if="::!data.sc_cat_item" >
<div class="panel panel-default">
<div class="panel-heading"><h4 class="panel-title">${Item not found}</h4></div>
<div class="panel-body wrapper">
<p>${This item is not found or currently not available}</p>
<p>${Suggestions}:</p>
<ul>
<li>${Try searching for the item}</li>
<li>${Go to the Service Catalog homepage}</li>
</ul>
</div>
</div>
</div>
<div class="sr-only" aria-live="assertive">{{c.status}}</div>
</div>
<script type="text/ng-template" id="modalTemplate">
<div class="panel" style="border: 5px solid deepskyblue;">
<div class="panel-body wrapper-x2" style="background: white;">
<center style="font-family:Adani Medium">
<i class="fa fa-check-square-o" style="font-size:48px;color:green"></i>
<h4 style="font-family:Adani Medium"><strong>{{c.head}}</strong></h4>
<h4 style="font-family:Adani Medium"><strong>{{c.secondHead}}</strong></h4>
<h4 style="font-weight: bold;" ng-bind-html="c.modal"></h4>
</center>
</div>
<div class="panel-footer text-right">
<button class="btn btn-default" style="float: left;" ng-click="c.returnHome()">${Return to Home}</button>
<button class="btn btn-success" ng-click="c.closeModal()">${Continue}</button>
</div>
</div>
</script>
Thanks for the response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2019 06:15 AM
I could try to help you to solve your problem if you provide enough information, so I'll be able to reproduce the problem. I think that such problem can be solved only after debugging.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2019 11:00 AM
Thanks for the response.
Here goes the implementation details,
I've a catalog item which has MRVS named, PR Line Items which has four "Single Line Text" variables named, item_description, quantity, rate, amount. It has a onchange catalog client script defined to calculate the amount from quantity and rate.
I suspect widget might be the cause of this issue but I haven't worked with SP and couldn't list out logical reasons for that. The reason is,
1. Widget is custom one cloned from SC Catalog Item deprecated widget.
2. It's been customized to display REQ number as a model dialog box intead OOB redirect to a new page.
Issue is whatever values or how many ever rows of data are added to MRVS, the array has zero rows.
I've shared server script, client script of the widget in my previous reply.
Appreciate your response.
🙂