- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2020 11:22 AM
Hey Wonderful Community.
I have a rather complex situation i'm hoping can be solved fairly simply.
Within the Service Portal, i'm creating a new page. I have 5 widgets on the page.
Widget
A. a "location" (reference) widget, a reference to the location table. using the <sn-record-picker>
B. a "status" (reference widget. a reference to the sys_choice table. using the <sn-record-picker>
C. A checkbox widget
D. an free text input box
E. a "reference field"
Now, hear me out. What i would like to do, using widgets A, B, C, D. I would like to:
Set a value in widget A. (do not want to broadcast anything)
Set a value in widget B. (do not want to broadcast anything)
Widget C is optional
When i set a value in Widget D, I want to get the value from Widget A, Get the value from Widget B, Get the value from Widget C, Do some server side scripting, then broadcast the results to Widget E.
Is there a way to have 1 widget gather data from the other widgets?
Or if i want to do this, will i need to combine all 4 of these widgets into a single widget? That way when i do the ng-onclick i can just gather all the values from the same widget?
Solved! Go to Solution.
- Labels:
-
Service Portal Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2020 07:04 AM
Not sure why you cannot give us a general jist of what you are doing but here is a place to start. Use the below in the appropriate widget client controller
//There are two ways to go about this, I'm showing both just as an example.
$scope.$on("field.change.location", function(evt, parms) {
$rootScope.$broadcast("new.selected.value.location", parms.newValue)
});
$scope.$on("field.change", function(evt, parms) {
if (parms.field.name == 'status'){
$rootScope.$broadcast("new.selected.value.status", parms.newValue)
}
});
For widget D do something like
$scope.$on("new.selected.value.location", function(event, data){
c.data.location = data;
);
then when they hit the button check to see if you have all of the values that you need and if so update the record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2020 11:55 AM
Hi,
Check this link below:
https://community.servicenow.com/community?id=community_blog&sys_id=e60eea2ddbd0dbc01dcaf3231f961972
If it was helpful, please give positive feedback.
Thanks,
☆ Community Rising Star 22, 23 & 24 ☆
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2020 12:59 PM
Why do you not want to use broadcast?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2020 04:15 PM
because i need to have Wiget A and widget B populated before any action takes place.
i'm going to use values from Widget A and Widget B to update a record which is entered in Widget D.
so when a change on Widget D happens, if i broadcast, that is sending that value to Widget E. but i need the values from A and B to do stuff before i send anything to E.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2020 09:05 AM
So just setup Widget D so that it does not broadcast anything until A & B have sent needed information and its work is done. This is just a bit of code to check some vars have data and act if they do.
The only three other options you have are
1 - Make a container widget and then have all the widgets children and try messing around with getting the child and parent scopes to set values. But then you have to monitor vars to see if they change and at that point you could have just use emit and broadcast to make things easier.
2 - Just make one big widget. I don't like this one but...
3 - Use client script to check to see if the HTML controls you need to get data from are on the page and if so use jquery to get the values. This can get really messy and it will probably just be easier to use emit and broadcast.
I have a Portal page that has a list of accounts in widget A, widget B shows account information, widget C is embeded in widget B and shows sub account information. I use broadcast when the user picks an account. That tells widget B what to load and widget C receives it also and finds the first sub-account record to load then does a broadcast to tell widget A what sub-account was selected so that widget A shows the selected sub-account as highlighted. Widgets B & C render but do not do anything until they have received data from Widget A, which is basically what you need to do. You just have another level of cascading.