0

I try to send the record in approval after the java runs. For example. I'm created new Custom JavaScript button that will check the conditions of start approval criteria. And after the window will be closed it must send the record for approval. The example code below:

{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")}
{!REQUIRESCRIPT('/js/functions.js')}
{!REQUIRESCRIPT('/resource/jQuery/jquery-1.8.2.min.js')}
{!REQUIRESCRIPT('/resource/jQuery/ui/jquery-ui-1.9.1.custom.min.js')}

requireCssFile('/resource/jQuery/ui/css/ui-lightness/jquery-ui-1.9.1.custom.min.css');

function requireCssFile(filename) {
  var fileref = document.createElement('link');
  fileref.setAttribute('rel', 'stylesheet');
  fileref.setAttribute('type', 'text/css');
  fileref.setAttribute('href', filename);
  document.getElementsByTagName('head')[0].appendChild(fileref);
}

//Variables
var j$ = jQuery.noConflict();
var poId = '{!Issues__c.Id}';
var results = sforce.connection.query("SELECT Status__c, Compliance_Contact_del__c, RecordType.Name, Trading_Contact_del_del__c, Legal_Address__c, Country_of_Incorporation__c, How_do_you_know_the_client__c, Source_of_funds__c, Account_Type__c, Client_has_website__c, Agency_Execution_3rd_Party_Settlement__c, Markets__c, OTC_Trading__c, Total_Monthly_notional_volumes__c, Actual_Annual_Revenue__c, Strategy__c, DVP_Settlement_with_another_broker__c, Company_Website__c, Client_Setup_with__c, Tariff_plan__c, General_Contact__c, Expected_Annual_Revenue__c FROM Issues__c WHERE Id = '" + poId + "'");
var po = results.records;
var msg = '<p>This Case cannot be sent for approval before following errors are amended:</p>';

if(poId == ''){
    poId = window.location.pathname.replace("/","");
}

//On-boarding Approval Process_new
if(po.RecordType.Name == 'Onboarding Institutional Client (Old ToBs)' || po.RecordType.Name == 'Onboarding institutional Client (New ToBs)' || po.RecordType.Name == 'Onboarding Institutional Client (US)' || po.RecordType.Name == 'Onboarding Individual Client'){
if(po.Status__c == 'Business Case approved' || po.Status__c == 'COF Approved by On-boarding Team' || po.Status__c == 'First email sent to client' || po.Status__c == "Waiting on client's pending documents" ||  po.Status__c == 'On-boarding requested' ||  po.Status__c == '4-eyes check' ||  po.Status__c == 'GMIB Compliance Approval' ||  po.Status__c == 'Compliance checked document pack, extra documents required from the Client' ||  po.Status__c == 'Compliance checked document pack, waiting for Client Committee approval' ||  po.Status__c == 'Risk Limits Assignment (by Gromov)' ||  po.Status__c == 'Top Management Approval (for high risk client)'){
    msg += '<br>&#8226; <u>Unexpected value of "<b>Status</b>" field:</u><br>&nbsp;&nbsp;&nbsp;Case Status suggests that Case is already in work.</br>';
}
if(po.Status__c == 'KYC Finalized' || po.Status__c == 'On-boarding finalized'){
    msg += '<br>&#8226; <u>Unexpected value of "<b>Status</b>" field:</u><br>&nbsp;&nbsp;&nbsp;Case Status suggests that Case is already finalized.</br>';
}
if(po.Status__c == 'Rejected by Compliance'){
    msg += '<br>&#8226; <u>Unexpected value of "<b>Status</b>" field:</u><br>&nbsp;&nbsp;&nbsp;Case Status suggests that Case got full reject from Compliance and so it can’t be initiated once again.</br>';
}
if(po.Compliance_Contact_del__c == null){
    msg += '<br>&#8226; "<b>Compliance Contact</b>" is blank</br>';        
}
if(po.Trading_Contact_del_del__c == null){
    msg += '<br>&#8226; "<b>Trading Contact</b>" is blank</br>';        
} 
if(po.Legal_Address__c == null){
    msg += '<br>&#8226; "<b>Client Address</b>" is blank</br>';        
}
if(po.Country_of_Incorporation__c == null){
    msg += '<br>&#8226; "<b>Country of Incorporation</b>" is blank</br>';        
}
if(po.How_do_you_know_the_client__c == null){
    msg += '<br>&#8226; "<b>How do you know the client</b>" is blank</br>';        
}
if(po.Source_of_funds__c == null){
    msg += '<br>&#8226; "<b>Source of funds</b>" is blank</br>';        
}
if(po.Account_Type__c == null){
    msg += '<br>&#8226; "<b>Account Type</b>" is blank</br>';        
}
if(po.Client_has_website__c == null){
    msg += '<br>&#8226; "<b>Client has Website</b>" is blank</br>';        
}
if(po.Agency_Execution_3rd_Party_Settlement__c == null){
    msg += '<br>&#8226; "<b>Agency Exec. / 3rd Party Settlement</b>" is blank</br>';        
}
if(po.Markets__c == null){
    msg += '<br>&#8226; "<b>Markets</b>" is blank</br>';        
}
if(po.OTC_Trading__c == null){
    msg += '<br>&#8226; "<b>OTC Trading</b>" is blank</br>';        
}
if(po.Total_Monthly_notional_volumes__c == null){
    msg += '<br>&#8226; "<b>Total Monthly notional volumes</b>" is blank</br>';        
}
if(po.Expected_Annual_Revenue__c == null){
    msg += '<br>&#8226; "<b>Expected Annual Revenue</b>" is blank</br>';        
}
if(po.Strategy__c == null){
    msg += '<br>&#8226; "<b>Strategy</b>" is blank</br>';        
}
if(po.DVP_Settlement_with_another_broker__c == null){
    msg += '<br>&#8226; "<b>DVP Settlement with another broker</b>" is blank</br>';        
}
if(msg != '<p>This Case cannot be sent for approval before following errors are amended:</p>'){
    var j$modalDialog = j$('<div></div>')
   .html(msg)
   .dialog({
        autoOpen: false,
        title: 'Approval submition error',
        resizable: false,
        width: 400,
        height: 400,
        autoResize: true,
        modal: true,
        draggable: false
    });
    j$modalDialog.dialog('open');
}
if(msg == '<p>This Case cannot be sent for approval before following errors are amended:</p>'){
    msg = '<center><font color="green"><b>Now the record can be submitted for approval</b></font></center>';
    var j$modalDialog = j$('<div></div>')
   .html(msg)
   .dialog({
        autoOpen: false,
        title: '<b>Success!</b>',
        resizable: false,
        width: 400,
        height: 400,
        autoResize: true,
        modal: true,
        draggable: false
    });
    j$modalDialog.dialog('open');

 }
 //Here I wan't to call action function like {!$Action.Case.Submit}

}

0

Just find the way to submit the record adding the new line:

window.location.replace("{!URLFOR($Action.Issues__c.Submit,Issues__c.Id )}");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.