Important Update: Community URLs redirect issues are partially resolved. Learn More. .

cancel
Showing results for 
Search instead for 
Did you mean: 

API Calls within Custom Objects

Arun.Prasad
Advocate II

Hello,

 

I have written a PowerShell script involving REST API calls to add users to requested Archer groups automatically post business approvals and close the request after user assignment (requests are tracked through an ODA). Now that I have a  working solution, I would like to have this invoked through a custom object button (within the record), rather than having it run through a Windows task on a scheduled basis. I know that we can place the script in the Archer server and hit it through the button. Is there any other way apart from placing the script on the server? Ideally, I am looking for a solution (API calls within custom object). 

 

Any thoughts or insights? Please let me know. Thanks.

 

Scott HagemeyerDavid PettyIlya Khen

13 REPLIES 13

Thank you so much Ilya Khen‌. I have completed the CO script with the help of above mentioned example.

Good

Hi Arun,

   Just checking to know how you were able to accomplish this solution? can you share the code if not restricted?

 

Regards,

Anil

Anli Kumar Bangalore Rajashekar,

 

I don't have the script handy. But, I quickly wrote something using the data feed button example posted above.

 

The below code uses an hard-coded request body (UserGroupstr) and it uses an account which has access to the Access Control module (refer "authstr"). If you would like to use the logged in user's session token, please refer my code in the following link: https://community.rsa.com/message/933979#comment-934096 (provided the user has enough privileges to perform the user assignment to a group).

 

Hope this helps..!!

 

<button type="button" onclick="approve()">Approve</button>

<script type="text/javascript">
var baseURL = window.location.protocol + '//' + window.location.host + parent.parent.ArcherApp.globals['baseUrl'];
var authstr = '{"InstanceName":"50000","Username":"serviceapi","UserDomain":"","Password":"R$ACharg3"}';
var UserGroupstr = '{"UserId":1470,"GroupId":16,"IsAdd":true}'
function approve() {
$.ajax
({
type: "POST",
url: baseURL+'/api/core/security/login',
contentType: "application/json",
dataType: "json",
data:authstr,
success: function (result) {
var stringresult = JSON.stringify(result);
var session = stringresult.substr(stringresult.search("SessionToken")+15,32);
//alert(session);
$.ajax
({
type: "PUT",
url: baseURL+'/api/core/system/usergroup',
contentType: "application/json",
dataType: "json",
headers: {
'content-Type': "application/json",
'Accept': "application/json",
'Authorization':session
},
data:UserGroupstr,
success: function (data) {
alert("User added to group");
},
error: function(errormsg) {
alert(JSON.stringify(errormsg.responseXML));
}
});
},
error: function(errMsg) {
alert(JSON.stringify(errMsg.responseXML));
}
});
$('#master_btnSave').click();
};
</script>