Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

curUserID() in Workflow

Posted on by 1,270

Hi,

  I'm trying to get the approving user out of a workflow.  In the completed method of the Workflow event handler the curUserId() method is called in an attempt to get the user who approved the process.  This value is then stored in a table for future reference.  The issue is the user returned is not the user who set off the approval.  I suspect the user context of the workflow event is separate from the user context of the front end.   When I run this code as a job the user is returned correctly.

  will curUserId() work within a workflow event handler?

Thanks

David

*This post is locked for comments

  • David Rose Profile Picture
    David Rose 1,270 on at
    RE: curUserID() in Workflow

    Thanks all,

    I actually found that when running in the context of the workflow, curuserid() never returned the correct value of the user who kicked off the workflow.  I had to workaround by putting another form in btween the submit button and the workflow running.  Running as the form the curuserid was picked up correctly then I went back to the workflow.  Doesn't nessesarily have to be a form

    David

  • David Rose Profile Picture
    David Rose 1,270 on at
    RE: curUserID() in Workflow

    Thanks Zeeshan,

     I've tried implementing this join for a quality order workflow but I'm having trouble getting it to return the correct values.  I haven't fully debugged it yet though.  With more effort perhaps I could make it work.

     I looked into the curUserID within the workflow and found that it was returning the admin user.  So as I expected it is returning the context of the system account running the workflow event not the use who submitted the approval.

     I'm now leaning towards capturing the approver in code just prior to sending the process off to the events handlers.

    Thanks

    David

  • Suggested answer
    RE: curUserID() in Workflow

    Below code fetches the user id’s who approved the PO workflow.

    select firstonly workflowtrackingstatustable

    join workflowtrackingtable

    where workflowtrackingstatustable .ContextRecId == purchtable.recid

    && workflowtrackingtable.TrackingContext == workflowtrackingcontext::WorkItem

    && workflowtrackingtable.TrackingType == workflowtrackingtype::Approval

    && workflowtrackingtable.WorkflowTrackingStatusTable == workflowtrackingstatustable .recid;

    {

    approvername = workflowtrackingtable.User;

    }

    Regards

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans