- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2018 07:42 AM
Hi
I'm in need of some help with a service portal widget. Here's what I've got so far: the widget displays a list of assets issued to the current user (using a glide record in the server script and ng-repeat in the HTML template). For each asset listed, I've also got a button which doesn't do much at the moment other than display a message (just to prove the click works).
What I want is for the user to be able to click the button along side a particular asset, to confirm they still have it, and for this to update the status / last confirmed date in the respective asset record.
Please can someone confirm the syntax:
- in the HTML template, to pass the sys_id back to the client script (via ng-click?)
- in the client script, to grab the sys_id and pass it on to the server script (via a function and c.server.update?)
- in the server script, to get the sys_id and update a glide record for the correct asset (via input?)
Thanks in advance.
Martin
Solved! Go to Solution.
- 12,396 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2018 12:34 PM
If you're using an ng-repeat with the buttons inside (I assume you are), you have access to the current model that you can pass into the ng-click, like this:
<div ng-repeat="asset in controller.assets">
<button ng-click="confirmAsset(asset);">Confirm!</button>
</div>
In your controller's ng-click handler (I named it confirmAsset here), you would do something like this:
// This is the confirmAsset method on your controller
this.confirmAsset = function(asset) {
// Asset is being bassed from the ng-click
// The controller has a server property with a method called get on it.
// The object you pass to the get() call is passed as "input" on the server-side code.
this.server.get({
// NOTE: This method property is totally unneeded technically.
// I am adding it here so that my server-side code can know exactly what it's supposed to do.
method: "confirmAsset",
asset_sys_id: asset.sys_id
});
}
The server side script would do something like this:
if (input) {
// Adding a method here just in case anything else sends information to the
// client side script, we can distinguish and only handle what we need to.
if (input.method === "confirmAsset") {
// NOTE: tableName here should be the name of the table
var record = new GlideRecord(tableName);
// NOTE: asset_sys_id should be the name of the field you want to update for
// confirmation
record.addQuery("asset_sys_id", input.asset_sys_id);
record.query();
if (record.next()) {
// NOTE: Set whatever field you're using to confirm the asset
record.confirmed = true;
// Update the record.
record.update();
}
}
}
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2024 06:04 AM
Hi Matthew,
We are on Vancouver:
Build name: Vancouver
Build date: 02-06-2024_1013
Build tag: glide-vancouver-07-06-2023__patch4-hotfix1b-01-25-2024
I've attached the XML for the OOTB 'Quick Links' widget which does have 'id="{{data.instanceId}}-item-{{$index}}"' within it so potentially it's something that was changed in the clone of the widget. That being said if we get it working in the OOTB widget I can duplicate in the customised widget.
To answer your question, yes the table is named - 'sn_ex_sp_employee_service_center_clicks'
I've also created the Quick Link column:
Thank you,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2024 07:24 AM
Ah ok. If you're already cloning/changing the widget and are not opposed, if you add that id attribute to each of the anchor tags that have the ng-repeat in them for the link render (there are a handful based on the types), the code should work there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2024 07:56 AM
What do you mean?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2024 08:09 AM
In the HTML template for your cloned widget, if you add that `id` attribute from above into each of the anchor tags, the code in the Link function will work.
My PDI is down at the moment, but when it comes up, I will load the widget, make some adjustments, and reattach it for you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-12-2024 07:06 AM
Hi Matt, were you able to get this working in your PDI? Even with the ID in the anchor tags it wasn't working for me.