'spModal: "shared" option
spModal seems to have an option called "shared" as per here: https://github.com/service-portal/x-archive/blob/master/documentation/spModal.md (scroll down to shared).
I am trying to get this to work.
In our service portal I have a page with a client script that loads a widget, I have added the "shared" option here as per above link:
function onLoad() {
if (g_scratchpad.canWrite && !g_form.isReadOnly('u_custom_company') && spModal) {
var wait = setInterval(function() {
var vendorEle = this.document.querySelector('#u_custom_company > .form-group');
if (!vendorEle) {
return;
}
var ccompany = {};
var btn = this.document.createElement('button');
btn.innerHTML = 'Add New Custom Company';
btn.className = 'btn btn-sm btn-primary m-t-sm';
btn.onclick = function() {
spModal.open({
title: 'Add New Custom Company',
widget: 'new_custom_company',
footerStyle: { display: "none" },
shared: ccompany
}).then(function() {
// Shared object was updated
console.log(ccompany);
});
};
vendorEle.appendChild(btn);
clearInterval(wait);
}, 500);
}
}
In the above script I keep getting "undefined" in the result of the console.log()
.
Then in the client script of my custom widget I am unsure how to assign a value to this shared variable so that the above client script has access to it. This is what I have tried so far:
function($scope) {
/* widget controller */
var c = this;
c.submit = function() {
if ( $('#name').val() && ( $('#idone').val() || $('#idtwo').val() )) {
c.data.action = 'createCustomCompany';
c.server.update().then(function() {
c.widget.options.shared = $scope.data.custom_companay.sys_id;
});
// close modal popup when submit is clicked
$scope.$parent.$parent.buttonClicked({ label: "Submit", submit: true });
} else {
$('.errormessage').show();
}
};
}
custom_company.sys_id
is being populated by my server script and contains a sys_id, for example of a newly created custom company record.
I am unsure how to hand over the data from $scope.data.custom_companay.sys_id
to the variable in the first client script?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|