Skip to main content
Nintex Community Menu Bar
Question

Problem with JavaScript Execute button

  • July 10, 2024
  • 6 replies
  • 13 views

Forum|alt.badge.img+2

I am trying to call apex web service using following code in salesforce and it working fine.
and I created javaScript  snippet code in skuid with some changes but I am getting an issue with this.Could please anyone help me to resolve this issue.

Salesforce :
sforce.connection.sessionId = “{!$Api.Session_ID}”;
orderedChkBox = “{!Opportunity.Ordered__c}”;
oppId = “{!Opportunity.Id}”;
idArray = {!GETRECORDIDS($ObjectType.OpportunityLineItem)};

if(idArray.length == 0)
{
alert(‘You have not selected any line items to convert.Please select the line items.’);
}
else if (idArray.length > 0)
{
var executionId =  “” +sforce.apex.execute(“createAgentCommission”,“convertLineItems”,{lineItemIds :idArray,oppId : oppId});

if(executionId == ‘The Line items which you have selected have already been converted.Please select a different line item.’ && executionId != null){
alert(executionId);
}
else{
alert(executionId);
location.reload(true);
}
}


SKUID JS Snippet:

var params = arguments[0],   list=params.list,
   selectedItems = list.getSelectedItems(),
   $ = skuid.$;
var records = skuid.$.map(arguments[0].list.getSelectedItems(),function(item){ 
return item.row.Id; 
}); 

alert(‘test’);
var opp = skuid.model.getModel(‘Application’);
var oppRow = opp.getFirstRow();
var orderedChkBox =oppRow.Ordered__c;
var oppId =oppRow.Id;
alert(oppId);
sforce.connection.sessionId = “{{$Api.Session_ID}}”; 
if(records.length === 0)
{
alert(‘You have not selected any line items to convert.Please select the line items.’);
}
else if (records.length > 0)
{
console.log(‘sforce-’+sforce.apex);
var executionId =  sforce.apex.execute(“createAgentCommission”,“convertLineItems”,{lineItemIds :records[0],oppId:oppId});
if(executionId == ‘The Line items which you have selected have already been converted.Please select a different line item.’ && executionId !== null){
alert(executionId);
}
else{
alert(executionId);
 window.location.reload();
}
}


This topic has been closed for replies.

6 replies

Forum|alt.badge.img+13

In the Skuid Snippet, you should remove this line because Skuid already sets sforce.connection.sessionId internally:

sforce.connection.sessionId = “{{$Api.Session_ID}}”; 

And change records[0] in this line to just be records:

var executionId =  sforce.apex.execute(“createAgentCommission”,“convertLineItems”,{lineItemIds: records, oppId: oppId});


Forum|alt.badge.img+2

Hi Zach

Thanks for the quick response.

I just made changes to my code according to your suggestions and tried still it didn’t execute apex class.

I made changes to my code like below but it didn’t get any result.

var params = arguments[0],   list=params.list,
   selectedItems = list.getSelectedItems(),
   $ = skuid.$;
var records =$.map(selectedItems,function(item){return item.row.Id;});
alert(‘test’);
var opp = skuid.model.getModel(‘Application’);
var oppRow = opp.getFirstRow();
var oppId =oppRow.Id;
alert(oppId);
if(records.length === 0)
{
    alert(‘You have not selected any line items to convert.Please select the line items.’);
}
else if (records.length > 0)
{
    console.log(‘sforce-’+sforce.apex);
    var executionId =  sforce.apex.execute(“createAgentCommission”,“convertLineItems”,{lineItemIds:records,oppId:oppId});
    if(executionId == ‘The Line items which you have selected have already been converted.Please select a different line item.’ && executionId !== null){
    alert(executionId);
}
else{
     alert(executionId);
     window.location.reload();
}
}


Forum|alt.badge.img+13

Are there any error messages in the JavaScript console, or in the Network tab? 


Forum|alt.badge.img+2

No errors occur Zach and When you click on button it didn’t respond anything.


Forum|alt.badge.img+13

Do you get any alerts?


Forum|alt.badge.img+2

Hi Zach the above code working fine for me.I made mistake previously instead of calling one snippet called wrong one.