You need to sign in to do that
Don't have an account?
I want to create save and approve button with Ajax Toolkit
I can approve a ProcessInstanceWorkitem using Apex or the API, but I just can't figure out how to write the same code using the Ajax Toolkit in javascript?
I see the Process Request function and the ProcessWorkItemRequest Function in the connection.js file, but not sure how to use it.
Below is the code to approve using Apex
//I query for the ProcessInstanceWorkitem associated to the parent object Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest(); req.setComments('Approving request.'); req.setAction('Approve'); req.setNextApproverIds(new Id[] {tumgr.Id}); //Use the ID from the newly created item to specify the item to be worked req.setWorkitemId(ProcessInstanceWorkitem.Id); //pass id queried //Submit the request for approval Approval.ProcessResult result = Approval.process(req); //Verify the results System.assert(result.isSuccess(), 'Result Status:'+result.isSuccess());
Any help is greatly apprieciated, thanks.
I was able to code this the old fashion way, through trail and error. I've included the code below.
var workItem = new sforce.ProcessWorkitemRequest(); workItem.action = "Approve"; workItem.workitemId = records[0].Id; workItem.nextApproverIds = "userrecord[0].Id"; workItem.comments = "Approving via Save&Approve JS button."; var processWorkItem = sforce.connection.process([workItem]);
All Answers
I was able to code this the old fashion way, through trail and error. I've included the code below.
var workItem = new sforce.ProcessWorkitemRequest(); workItem.action = "Approve"; workItem.workitemId = records[0].Id; workItem.nextApproverIds = "userrecord[0].Id"; workItem.comments = "Approving via Save&Approve JS button."; var processWorkItem = sforce.connection.process([workItem]);
Not sure if you can clearify exactly what you are doing here or not? I am looking to have a submit for approval button at the top of the record instead of on the related list. Is there an easy way about that or should I create a new post?