- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2024 08:23 AM - edited ‎03-14-2024 08:24 AM
I have cloned the "SC ORDER STATUS" Widget because I need to add a custom button for every opened RITM. The button should not appear when the RITM's state is "closed complete". However, the condition to show the button in my HTML code doesn't seem to be working, and I'm not sure why. Below is the code. Thanks in advance.
<td>
<div class="panel-body" >
<button type="button" class="btn btn-primary btn-block" ng-click="c.uiAction('resolve', requestItem.sys_id)" ng-if="c.requestItem.state !='3'">Conferma Acquisto</button>
</div> </td>
CLIENT SCRIPT
function test() {
c.uiAction = function(action,myRitm) {
c.data.action = action;
c.data.ritm = myRitm;
alert(action);
alert(myRitm)
c.server.update().then(function(test) {
c.data.action = undefined;
})
}
}
SERVER SCRIPT
(function(test) {
// Get table & sys_id
data.table = input.table || $sp.getParameter("table");
data.sys_id = input.sys_id || $sp.getParameter("sys_id");
gs.log("MIAO MIAO data.table " + data.table);
if (data.table == 'sc_request') {
gr = new GlideRecord(data.table);
// Valid GlideRecord
gr = new GlideRecord(data.table);
if (!gr.isValid())
return;
// Valid sys_id
if (!gr.get(data.sys_id))
return;
gs.log("miao miao miao SYSID" + data.request.requestItems);
var grReqItem = new GlideRecord("sc_req_item");
grReqItem.addQuery('request', gr.sys_id);
grReqItem.addQuery('sys_id',input.ritm)
gs.log("MIAO MIAO MIAO QUERY SC REQ ITEM" + grReqItem.addQuery('request', gr.sys_id));
grReqItem.query();
var action = input.action;
gs.log("MIAO MIAO action" + action + " test " + input.ritm);
if(grReqItem.next()){
gs.log(("grReqItem.next() " + grReqItem.getRowCount()));
gs.log(("grReqItem.next() " + grReqItem.getRowCount() + "" + grReqItem.number));
grReqItem.setValue('state', 3);
grReqItem.update();
}
if (action == 'resolve') {
gs.log("MIAO MIAO MIAO ALL INTERNO DELL ACTION RESOLVE")
grReqItem.setValue('state', 3);
grReqItem.setValue('stage', 'fulfillment');
grReqItem.update();
}
}
})();
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2024 02:10 AM
I have resolved the issued, just adding in oob code the state "steatment". Thx for ur support.
data.request.requestItems.push({
sys_id: reqItemGr.sys_id.getValue(),
name: catItem.name,
delivery_date: ritm.getDeliveryDueDate(),
stage: reqItemGr.stage.getValue(),
state:reqItemGr.state.getValue(), //custom <---------HERE I RETRIEVE THE STATE
number: reqItemGr.number.getValue(),
quantity: reqItemGr.quantity.getValue(),
show_quantity: catItem.show_quantity,
show_delivery_time: catItem.show_delivery_time,
price: parseFloat(reqItemGr.price.getValue()),
price_dv: reqItemGr.price.getDisplayValue(),
recurring_price: parseFloat(reqItemGr.recurring_price.getValue()),
recurring_price_dv: reqItemGr.recurring_price.getDisplayValue() + ' ' + frequency_dv,
requested_for: reqItemGr.getDisplayValue("requested_for"),
requested_for_id: reqItemGr.getValue("requested_for"),
showPrice: showItemPrice,
showRecurringPrice: showItemRecurringPrice,
total_price: itemTotalPrice,
total_price_dv: spCurrencyFormatter.format(itemTotalPrice),
total_reccuring_price: itemTotalRecurringPrice,
total_reccuring_price_dv: spCurrencyFormatter.format(itemTotalRecurringPrice) + ' ' + frequency_dv,
stageWidget : $sp.getWidget("cb6631d39f2003002899d4b4232e7030", {req_item_id: reqItemGr.sys_id.getValue(), onload_expand_request_item_stages: false})
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2024 09:00 AM
Looking at the code you provided, I believe you need a record watcher in you client controller that watches that record. And that binds to your ng-if tag.
That should listen to the changes in the request, and when its closed, it should populate that button.
Hopefully that helps! Good luck 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2024 09:18 AM
Thank your for your Reply, i have tried this, but doesnt work, maybe the problem was i cant reach the value of state with dot notation.
Client Controller
function test() {
//controller watcher
$scope.$watch('requestItem.state', function(newValue, oldValue) {
if (newValue == 3) {
$scope.showConfirmButton = true;
} else {
$scope.showConfirmButton = false;
}
});
//
c.uiAction = function(action,myRitm) {
c.data.action = action;
c.data.ritm = myRitm;
alert(action);
alert(myRitm)
c.server.update().then(function(test) {
c.data.action = undefined;
})
}
<td>
<div class="panel-body" >
<button type="button" class="btn btn-primary btn-block" ng-click="c.uiAction('resolve', requestItem.sys_id)" ng-if="showConfirmButton">Conferma Acquisto</button>
</div>
<!-- bottone CUSTOM FINE-->
</td>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2024 09:34 AM
If the value is on another record (dot walked) I believe you'd have to look up and watch that record specifically. I don't believe it works for dot walking to other records.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2024 10:02 AM
the record is inside the "requestItem", infact inside the log everytime i click on the button based i retrieve the correct sys_id of the record. But i dont understand why i cant reach the state of ritm.
Infact here i can retrieve all information about sc_req_item
<tr ng-repeat="requestItem in ::data.request.requestItems">