Need help to convert a widget code to UI Macro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2019 08:29 AM
Hi all,
I have created a widget which works similar to reference variable to show active user records on one of the catalog item. Did it so because when I use the variable attributes on the list collector or reference type variables to show extra informartion about user and if those fields are empty they are misaligned. The works well on the portal but when I see it on RITM in itil view, it just shows label of the variable not the text field. Need to show that on RITM after submitting it. So, need to convert it to UI Macro in order to show it on the RITM where I am not familiar with the jelly scripting to do that.
Here is my code:
----HTML----
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Location</h4>
</div>
<div class="panel-body">
<sn-record-picker
field="name"
table="'sys_user'"
display-field="'name'"
display-fields="'user_name,title,email'"
value-field="'sys_id'"
search-fields="'name'"
page-size="100" >
</sn-record-picker>
</div>
</div>
---------------client script----------
function($scope, spUtil) {
var c = this;
$scope.user = {
displayValue: c.data.user.name,
value: c.data.user.sys_id,
name: 'name'
};
$scope.$on("field.change", function(evt, parms) {
if (parms.field.name == 'name')
c.data.setLocation = parms.newValue;
c.server.update().then(function(response) {
spUtil.update($scope);
})
});
}
----------------server script----------
(function(){
var userSysId = "";
if (input.setLocation)
userSysId = input.setLocation;
else
userSysId = gs.getUser().getRecord();
var userGR = GlideRecord('sys_user');
userGR.get(userSysId);
data.user = {};
$sp.getRecordDisplayValues(data.user, userGR, 'sys_id,user_name,title,email');
})();
Really appreciate anyone's help on this.
Thanks,
Murali Pasikanti
- Labels:
-
Request Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2019 10:54 AM
Hi Marius,
Yes I wanted to do what you have done initially to copy the value from the widget variable to a text variable on the catalog item but as per my code that I have mentioned before, I am trying to do it in this way,
$scope.$watch($scope.user.displayValue, function(newVal, oldVal) {
$scope.page.g_form.setValue('users', newVal);
});
But after submitting the form, the value copied to the catalog item variable on RITM
show as,
Can you guide me with this
Thanks
Murali Pasikanti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2019 12:51 AM
Ah! I see
In that case, I would recommend you to change from $scope.$watch to using an on-change attribute on the sn-record-picker, with the g_form.setValue in an accompanying function like this:
------- HTML -------
<sn-record-picker
on-change="changeFunc()" // <----
field="name"
table="'sys_user'"
display-field="'name'"
display-fields="'user_name,title,email'"
value-field="'sys_id'"
search-fields="'name'"
page-size="100" >
</sn-record-picker>
------- Client -------
$scope.changeFunc = function() {
$scope.page.g_form.setValue('users', $scope.name.displayValue);
}
This should set the field accordingly.
Alternatively, if the variable you wish to populate is a reference variable, I would change from $scope.name.displayValue to $scope.name.value, as this will set the sys_id of the reference picker. But in that specific case, you might as well just use a reference variable, instead of a widget. 😉
Please mark my contributions as helpful, if they were!
/Marius
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2019 10:41 AM
Hi Marius,
Thanks for taking time to help me out. Unfortunately it did not work in my scenario. Finally I found out from one of the post's on community that below part of code works for me and it did.
$scope.$on("field.change", function(evt, parms) {
if (parms.field.name == c.name.name){
$scope.page.g_form.setValue('caller',parms.field.value);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2019 05:57 PM
Hi Murali,
I've got to be honest, I don't quite understand the purpose of your widget. However, if you're trying to find a replacement for the snRecordPicker directive in jelly, the closest thing would be to embed the ui-reference macro in your macro:
https://YOUR_INSTANCE.service-now.com/nav_to.do?uri=sys_ui_macro.do?sys_id=0b8530f30a0a0a70004c1134d0d30659
The macro itself has documentation on what parameters it accepts and this link is an example on how you would embed it:
https://YOUR_INSTANCE.service-now.com/nav_to.do?uri=sys_ui_macro.do?sys_id=98a971f6c0a8002700e2b748788f753f