how can I using rest api in customCode?

I have added 'customCode' to a field in detailviewdefs.php for campaign module.  I want to populate a dropdown with some other values using a custom endpoint.

'customCode' => '<script type="text/javascript" src="custom/js/custom.js?v13225"></script><script>load_linked_vouchers("' . $focus->id . '")</script>'

so it loads my js file, and then runs a function comtained inside the js file, passing the record ID to the function.

Then in my custom.js I have the function

function load_linked_vouchers(id) {
    $.ajax({
        beforeSend: function (request) {
            request.setRequestHeader("OAuth-Token",SUGAR.App.api.getOAuthToken());
},
url: "rest/v10/Campaigns/" + id + "/link/igsm_igsmk_vouc_campaigns_1",
dataType: "json",
type: "GET",
}).done(function (response) {
console.log(response);
})
}

I get "Cannot read property 'api' of undefined" javascript error. I dont know why it SUGAR.App is undefined because it shows in the console so it must be global. Is the customCode ran seperately? how can I put the SUGAR.App into it? Am I doing this wrong or is there a better way?

Parents
  • I just realized you are talking about  detailviewdefs.php and rest v10.

    rest v10 is in SugarCRM 7.x and detailviewdefs.php went away for all sidecar modules with the release of v7.

    What version are you running? Is this a module in running in Backwards Compatible mode in v.7.x?


    FrancescaS

  • IT WORKED! You just saved me so much headache.  Thank you so much!

Reply Children
No Data