Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

Create New record (with code) after Workflow Submit

Posted on by Microsoft Employee

Hello everyone, som i'm trying to create a new record in Planned answer Session after i submit my workflow i used these code but it doesn't work 

  public void completed(WorkflowElementEventArgs _workflowElementEventArgs)
	{
		// TODO:  Write code to execute once the workflow is completed.
        RecId documentRecId = _workflowElementEventArgs.parmWorkflowContext().parmRecId();
        NouvelleMesureTable::updateWorkflowStatus(documentRecId, GD_WFDocumentStatus::Valide);
        FormControl sender;
        FormRun formRun;
        Args args = new Args();
        KMVirtualNetworkAnswerTable kMVirtualNetworkAnswerTable;
        NouvelleMesureTable nouvelleMesureTable;
        FormDataSource nouvelleMesureTable_ds  = sender.formRun().dataSource(formDataSourceStr(NouvelleMesureDisciplinaire,NouvelleMesureTable))as
            FormDataSource;
       
        
       
        ttsbegin;
        kMVirtualNetworkAnswerTable.ExecutedBy=nouvelleMesureTable.Person;
        kMVirtualNetworkAnswerTable.EvaluationOf=nouvelleMesureTable.Person;
        kMVirtualNetworkAnswerTable.kmCollectionId=nouvelleMesureTable.Questionnaire;

        ttscommit;

        args.name(formStr(NouvelleMesureDisciplinaire));
        formRun = classFactory.formRunClass(args);
        formRun.init();
        formRun.run();
	}

thank you.

  • Verified answer
    Komi Siabi Profile Picture
    Komi Siabi 12,666 Most Valuable Professional on at
    RE: Create New record (with code) after Workflow Submit

    Hi wassim77,

    Great you have it resolved now!

    So you are providing answers to a questionnaire which is already defined on NouvelleMesureTable. Meanwhile, what I got was, assigning questionnaire which employee would and provide answers to from ESS.

    Bravo :)

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Create New record (with code) after Workflow Submit

    So i fixed it, the Answertable was the way to go.

    i wasn't getting the number seq that was fault 

    thank you for your help 

    
                NouvelleMesureTable nouvelleMesureTable;
                KMVirtualNetworkAnswerTable kMVirtualNetworkAnswerTable;
                nouvelleMesureTable = NouvelleMesureTable::findRecId(document.RecId);
                kMVirtualNetworkAnswerTable.EvaluationOf = nouvelleMesureTable.Person;
                kMVirtualNetworkAnswerTable.ExecutedBy = nouvelleMesureTable.Person;
                kMVirtualNetworkAnswerTable.kmCollectionId = nouvelleMesureTable.Questionnaire;
                kMVirtualNetworkAnswerTable.status = KMCollectionAnswerStatus::Planned;
                kMVirtualNetworkAnswerTable.kmVirtualNetworkAnswerTableId = NumberSeq::newGetNum(KMKnowledgeCollectorParameters::numRefCollectionAnswerId()).num();
    
                kMVirtualNetworkAnswerTable.insert();

  • Komi Siabi Profile Picture
    Komi Siabi 12,666 Most Valuable Professional on at
    RE: Create New record (with code) after Workflow Submit

    Hello,

    Can you tell me how you are getting the worker NouvelleMesureTable?

    Are you using the recId or the personnelNumber? And how are you able to detect the worker in the document. And lastly, show us the complete code and where you are inserting records in the tables above.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Create New record (with code) after Workflow Submit

    yes i understand so i used the the tables, the person didn't get the questionnaire so i went to check the records in the tables what was missing and i found that HRMVirtualNetworkGroupRelation was not inserting person and hrmVirtualNetworkGroupId

    pastedimage1666132488750v1.jpeg

    this is my code 

    NouvelleMesureTable nouvelleMesureTable;
                HRMVirtualNetworkGroup  hRMVirtualNetworkGroup; 
                HRMVirtualNetworkGroupRelation  hRMVirtualNetworkGroupRelation; 
                KMCollectionRights  kMCollectionRights;  
    
                
                hRMVirtualNetworkGroupRelation.hrmVirtualNetworkGroupId = nouvelleMesureTable.hrmVirtualNetworkGroupId;
                hRMVirtualNetworkGroupRelation.Person = nouvelleMesureTable.Person;
                hRMVirtualNetworkGroupRelation.insert();
    
     
                kMCollectionRights.kmCollectionId = nouvelleMesureTable.Questionnaire ;
                kMCollectionRights.hrmVirtualNetworkGroupId = nouvelleMesureTable.hrmVirtualNetworkGroupId; 
                kMCollectionRights.insert();

  • Komi Siabi Profile Picture
    Komi Siabi 12,666 Most Valuable Professional on at
    RE: Create New record (with code) after Workflow Submit

    So focusing on kMVirtualNetworkAnswerTable is a wrong move.

    kMVirtualNetworkAnswerTable  will be populated only after the employee had attended to the questionnaire. So for now, please ignore kMVirtualNetworkAnswerTable.

    I have highlited the tables you should focus on already above. Please, review and if you have difficulties, ask, then we will take it one after the other.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Create New record (with code) after Workflow Submit

    it's to assign questionnaire to employee on ESS

  • Komi Siabi Profile Picture
    Komi Siabi 12,666 Most Valuable Professional on at
    RE: Create New record (with code) after Workflow Submit

    Hi wassim77,

    Please, what is your requirement ?

    to assign questionnaire to employees on ESS.

    OR

    to assign answers to questionnaire ?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Create New record (with code) after Workflow Submit

    okey so i fixed it it was the "ignore EDT relation" set to yes.

    i get a drop down box where i can select the but it's the same thing i can't get the records into KMVirtualNetworkAnswerTable

    by the way thank so much for you're help komi

  • Komi Siabi Profile Picture
    Komi Siabi 12,666 Most Valuable Professional on at
    RE: Create New record (with code) after Workflow Submit

    Did you add relations ?

    Does the table have a record ?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Create New record (with code) after Workflow Submit

    So i added hrmVirtualNetworkGroupId to my table but i'm getting an empty field

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,900 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,297 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans