Custom variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2022 11:12 AM
i have a custom variable and that needs to display message on the basis of another variable. how can i achieve that?
i am trying to create a macro which accept value from another variable in catalog item and displays msg on that basis of that. if user select variable 'A' then msg for A has to be displayed if not msg B is displayed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2022 11:37 AM
I did something similar with a widget. I had a hidden variable called `sp_message` and would set the value to a string of JSON for what I wanted to display
The value would be something like `{type: "warning", message: "text goes here"}`, and a box would appear with the appropriate styling and message. You could probably do it right on the widget but I wanted the displayed message logged/saved with the ticket in case it needed to be referenced.
HTML
<div class="alert ng-scope" ng-class="{'alert-danger' : c.data.type == 'error', 'alert-warning' : c.data.type == 'warning' || c.data.type == 'note', 'alert-success' : c.data.type != 'warning' && c.data.type != 'error'}" style="">
<span ng-if="c.data.type == 'error'" class="fa fa-exclamation-triangle m-r-xs ng-scope" aria-label="Error. "></span>
<span ng-if="c.data.type == 'warning'" class="fa fa-exclamation-triangle m-r-xs ng-scope" aria-label="Warning. "></span>
<span ng-if="c.data.type == 'tip'" class="fa fa-paperclip m-r-xs ng-scope" aria-label="Tip. "></span>
<span ng-if="c.data.type == 'note'" class="fa fa-thumb-tack m-r-xs ng-scope" aria-label="Note. "></span>
<span ng-bind-html="c.data.message" class="ng-binding"></span>
</div>
Client Controller
function($rootScope, $scope) {
/* widget controller */
var c = this;
if ($scope.page.field.value) {
c.data = JSON.parse($scope.page.field.value);
console.info(c.data);
}
$rootScope.$on("field.change", function(evt, parms) {
if (parms.field.name == 'sp_message' && parms.field.value) {
c.data = JSON.parse(parms.field.value);
console.info(c.data);
}
});
}