- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2017 01:10 AM
Hello.
In order to simplify my question I've created a new ui macro variable that contain only a single input field:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<input type="text" id="test" name="test"></input>
</j:jelly>
In order to view the variable the catalog form I've connected a new widget to the macro variable that contain the same field:
Body HTML template:
<div>
<input type="text" id="test" name="test" />
</div>
And indeed the new variable is shown on the catalog form as input field in the new service portal, but when i submit the catalog with some string inside the input field the variable value stay empty:
I tried several methods in order to set the value in the variable but unfortunately i didn't succeed. my only concern is how to set the value in the widget, not in the macro.
Thank you/
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2017 04:33 AM
Hi
Values entered in widget variables are NOT saved when you submit the item.
You need to add additional regular variables (eg. a single line text) and then on an onSubmit script (only for ui macros on the old service catalog) copy the value from your widget to the regular variable. You can hide the regular variable using a UI policy.
Making your own widget for SP, you will not be able to access the content with an onSubmit script, as you can't accces the DOM. Instead you build an onChange logic into your widget to copy the value from the input field to your regular variable everytime a change happens.
You can access variables on the catalog item from the widget via:
$scope.page.g_form.setValue('var_name');
Also see how to monitor for changes in catalog variables here: Embedding widgets in Service Catalog - ServicePortal.io - Service Portal, CMS, and Custom Apps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2017 10:06 PM
yes, i have declared $scope declared as a service in the client script function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-12-2017 01:17 AM
Can you show me the script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-12-2017 03:58 AM
The Widget is for converting the "hours:minutes:seconds" to duration type value. below is the script.
HTML:
<table>
<th>Downtime</th>
<tr>
<td>Hours</td>
<td>Minutes</td>
<td>Seconds</td>
</tr>
<tr>
<td><input type="number" ng-model="c.hours" ng-change="change()" min="0" max="9999" id="hours" /></td>
<td><input type="number" ng-model="c.minutes" ng-change="change()" min="0" max="9999" id="minutes" /></td>
<td><input type="number" ng-model="c.seconds" ng-change="change()" min="0" max="9999" id="seconds" /></td>
</tr>
</table>
Client Controller:
function($scope) {
/* widget controller */
var c = this;
$scope.change=function()
{
var hours = c.hours;
var minutes = c.minutes;
var seconds = c.seconds;
console.log(c.hours+","+c.minutes+","+c.seconds);
console.log("hrs:mts:sec:"+ hours+":"+minutes+":"+seconds);
var durationField = hours+":"+minutes+":"+seconds;
var sp=durationField .split(':');
var sec = sp[0]*3600+sp[1]*60+sp[2]*1;
var val= parseInt(sec);
var days=Math.floor(val/(86400));
var hrs=Math.floor((val-days*86400)/3600);
var mts=Math.floor((val-days*86400-hrs*3600)/60);
var secs=Math.floor(val-days*86400-hrs*3600-mts*60);
var finalduration=days+" "+hrs+":"+mts+":"+secs;
console.log(finalduration);
var g_form = $scope.page.g_form;
g_form.setValue('sg_outage_duration',finalduration); // variable name sg_outage_duration
}
}
Thanks to help..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-12-2017 04:59 AM
Skip the step where you try to create a variable on the Angular service and just do it in one line:
$scope.page.g_form.setValue('sg_outage_duration',finalduration);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-12-2017 05:41 AM
Thanks, It worked.