function SaveAsDraft() { alert("Inside SaveAsDraft"); //Update Approval Status setFieldValue("Approval_x0020_Status", "Pending Submission"); alert(getFieldValue("Approval_x0020_Status")); //Call the workflow var wfID = CallWFAPI_ONDraft(); alert("Id Returned from Workflow : " + wfID ); //Save the form $("input[id$='diidIOSaveItem']").trigger("click"); } function CallWFAPI_ONDraft() { var auth = btoa('uid:pwd'); var _id; $.ajax({ type: 'GET', url: 'my service url goes here', headers: { "Authorization": "Basic " + auth }, success : function(data) { console.log(data); _id = data.id; setFieldValue("WF_ID",data.id); alert("Value of _id = " + _id); alert( "Get Field Value WF_ID" + getFieldValue("WF_ID")); }, }); alert("After calling the API Get Field Value WF_ID" + getFieldValue("WF_ID")); return getFieldValue("WF_ID"); }