Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / multiselect lookup on ...
Finance forum
Unanswered

multiselect lookup on form contrl

Posted on by 1,457
I have code on multiselect lookup on form string control , the lookup is opening but not taking values ,can anyone guide me on this .
  • Layan Jwei Profile Picture
    Layan Jwei 4,742 Super User on at
    multiselect lookup on form contrl
    Hi Dinesh,
     
    What do you mean not taking any values?
    Do you mean that after you multi select values, then you click select, the values are not being filled in the control?
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    multiselect lookup on form contrl
    [ExtensionOf(classStr(PSAProjInvoiceProposalSubmitToWF))]
    final class DTPSAProjInvoiceProposalSubmitToWF_Extension
    {
       //  Description    : test if the invoice proposal can be submitted to workflow
       public static void main(Args _args)
        {
            RecID                   recID               = _args.record().RecId;
            TableId                 tableId             = _args.record().TableId;
            ProjProposalJour        projProposalJour    = _args.record();
            WorkflowWorkItemTable   workItem            = _args.caller().getActiveWorkflowWorkItem();
            WorkflowSubmitDialog    workflowSubmitDialog;
            WorkflowComment         wfComment;
            workflowTypeName        workflowTemplateName = workFlowTypeStr('PSAProjInvoiceProposal');
            PSAProjProposalProj     pSAProjProposalProj;
            ProjOnAccTrans          projOnAccTrans;
            ProjProposalOnAcc       projProposalOnAcc;
            ProjItemTrans           projItemTrans;
            ProjProposalId          proposalId;
            ReasonTableRef          reasonTableRef;
            ProjParameters          projParameters;
            ProjInvoiceId           strInvoiceId;
            str                     value,type1,type2;
            ProjOnAccTransId        transid;
            PSAContractLineNum      lineNum;
    
            //strInvoiceId = projProposalJour.ProjInvoiceId;
            //value        = subStr(strInvoiceId,1,3);
            proposalId = projProposalJour.ProposalId;
    
            if (projProposalJour.RecId != 0)
            {
                while select InvoicedNow,ContractLineNum from pSAProjProposalProj
                where  pSAProjProposalProj.ProjProposalId ==  projProposalJour.ProposalId
              
                {
                    select firstonly projParameters
                            where  projParameters.DataAreaId == projProposalJour.DataAreaId;
    
                    select TransId from projProposalOnAcc
                        where projProposalOnAcc.ProposalId == projProposalJour.ProposalId;
    
                    transid = projProposalOnAcc.TransId;
    
                    select TransactionOrigin FROM projOnAccTrans
                       where projOnAccTrans.TransId ==  transid;
    
                    lineNum = pSAProjProposalProj.ContractLineNum;
                   
                    //select TransactionOrigin from  projItemTrans
                    //    where ProjItemTrans.PSAContractLineNum ==  lineNum;
    
                    //type1  = enum2Str(projOnAccTrans.TransactionOrigin) ;
                    //type2  = enum2Str(projItemTrans.TransactionOrigin) ;
                    //info(strFmt("%1-%2",lineNum,PSAProjProposalProj.InvoicedNow));
    
                    //if( type2 != 'Deduction')
                    //{
                        if( PSAProjProposalProj.InvoicedNow <= 0 &&   lineNum != '' )
                        {
                            select Reason,RecId from   reasonTableRef
                                where   reasonTableRef.RecId ==  projProposalJour.ReasonTableRef;
    
                            if(projParameters.DTOriginalInvoiceMandatory == NoYes::Yes &&  projProposalJour.DTOriginalTaxInvoiceNo == ''
                                && projParameters.DTReasonCodeMandatory == NoYes::Yes && ReasonTableRef.Reason == '')
                            {
                                throw error("The Original Invoice field & Reason Code field is mandatory. Cannot proceed further.");
                                //                    //ret = ret && false;
                            }
                            else if(projParameters.DTOriginalInvoiceMandatory == NoYes::Yes &&  projProposalJour.DTOriginalTaxInvoiceNo == '')
                            {
                                throw error("The Original Invoice field is mandatory. Cannot proceed further.");
                                //ret = ret && false;
                            }
                            else if(projParameters.DTReasonCodeMandatory == NoYes::Yes && ReasonTableRef.Reason == '')
                            {
                                throw error("The Reason Code field is mandatory. Cannot proceed further.");
                                //ret = ret && false;
                            }
    
                        //}
                    }
                }
    
            }
    
            // Make the form refresh its common workflow UI controls.
            PSAProjInvoiceProposalSubmitToWF::refreshCaller(_args);
            next Main(_args);
        }
    
    }
    
    Code to throw error on work flow submit button .
    
    1)Code on post button of dialog 
    
    To trigger the error on post button need to do code on the dialog form .
    [ExtensionOf(formstr(WorkflowWorkItemActionDialog))]
    final class DTCreditNoteworkflowWorkItemActionDialogForm_Extension
    {
        public void  closeOk()
        {
            WorkflowWorkItemTable       workItemTable;
            WorkflowVersionTable        versionTable;
            SysWorkflowTable            sysWorkflowTable;
            SysWorkflowElement          sysWorkflowElement;
            ProjParameters              projParameters;
            PSAProjProposalProj        pSAProjProposalProj;
            ProjProposalJour           projProposalJour;
            ReasonTableRef               reasonTableRef;
            ProjProposalId              proposalId;
            DataAreaId                 areaId;
            RecId                      recId;
            WorkflowOutcomeName         outcomeName;
            LabelString                 menuItemLabel = '';
            ;
    
            workItemTable = workflowWorkItemActionDialog.parmWorkItem(); 
            select projProposalJour 
                where projProposalJour.RecId == workItemTable.RefRecId
                &&   projProposalJour.TableId == workItemTable.RefTableId;
     
            proposalId = projProposalJour.ProposalId;
            areaId     = projProposalJour.DataAreaId;
            recId      = projProposalJour.ReasonTableRef;
    
            if (workItemTable.RecId != 0)
            {
                versionTable = workItemTable.workflowVersionTable();
                sysWorkflowElement = SysWorkflowElement::newElementTable(workItemTable.workflowElementTable());
     
                outcomeName = WorkflowWorkItemActionManager::findOutcomeNameForMenuItem(workItemTable,
                                                                                        workflowWorkItemActionDialog.parmWorkItemActionMenuFunc().AOTname());
     
                if ((strLen(outcomeName) > 0) && (workItemTable.Type != WorkflowWorkItemType::Recall))
                {
                    menuItemLabel = sysWorkflowElement.ActionMenuItemLabel(outcomeName);
                }
                else
                {
                    menuItemLabel = workflowWorkItemActionDialog.parmWorkItemActionMenuFunc().label();
                }
     
                if(versionTable.workflowTable().Name == "Review project invoice proposals" &&  menuItemLabel == "Post")
                {
                    //if(strLTrim(this.parmWorkflowWorkItemActionDialog().parmWorkflowComment(comment.text())) == "")
                    //{
                    //    throw error ("Please enter Comment..");
                     //}
                   
                   
            while select InvoicedNow from pSAProjProposalProj
                where  pSAProjProposalProj.ProjProposalId == proposalId
                    
                    {
                        select firstonly projParameters
                            where  projParameters.DataAreaId == areaId;
    
                        if( PSAProjProposalProj.InvoicedNow <= 0)
                        {
                         
                            if(projParameters.DTOriginalInvoiceMandatory == NoYes::Yes && projProposalJour.DTOriginalTaxInvoiceNo == ''
                                && projParameters.DTReasonCodeMandatory == NoYes::Yes && ReasonTableRef.Reason == '')
                            {
                                throw error("The Original Invoice field & Reason Code field is mandatory. Cannot proceed further.");
                            }
                        }
    
                        if( PSAProjProposalProj.InvoicedNow <= 0)
                        {
                         
                            if(projParameters.DTOriginalInvoiceMandatory == NoYes::Yes && projProposalJour.DTOriginalTaxInvoiceNo == '')
                            {
                                throw error("The Original Invoice field is mandatory. Cannot proceed further.");
                            }
                        }
    
                        if( PSAProjProposalProj.InvoicedNow <= 0)
                        {
                            select Reason,RecId from   reasonTableRef
                                where   reasonTableRef.RecId == recId  ;
    
                            if(projParameters.DTReasonCodeMandatory == NoYes::Yes && ReasonTableRef.Reason == '')
                            {
                                throw error("The Reason Code field is mandatory. Cannot proceed further.");
                            }
                        }
                    }
                }
            }
     
                
     
            next  closeOk();
        }
    
    }
    
    2)Code on click button of form 
    /// <summary>
    /// //<DT-DK> <DT_3130_CreditNotesInvoiceParameters_DK> <13-01-2024> -Start
    //Ticket #3130_throw error on post button .
    /// extension of form control: ProjInvoiceProposalDetail: postButton
    /// </summary>
    [ExtensionOf(formControlstr(ProjInvoiceProposalDetail,ProjFormLetter_Invoice))]
    final class DTInvoicepropCreditnt_Extension
    {
       /* public void clicked()
        {
            FormButtonControl formButtonControl = any2Object(this) as FormButtonControl;
          
            FormDataSource     formDatasource     = formButtonControl.formRun().dataSource(tableStr(ProjProposalJour));
            ProjProposalJour   projProposalJourds = formDatasource.cursor();
            FormControl        formControl =  formButtonControl;
            FormRun            formRun = formControl.formRun();
            FormStringControl     ReasonCode  = formRun.design().controlName(formControlStr(ProjInvoiceProposalDetail, Reason_M_editReasonCode )) as   FormStringControl ;
            PSAProjProposalProj    pSAProjProposalProj;
            ProjParameters     projParameters;    
           
    
            select firstonly projParameters;
    
           while select InvoicedNow from PSAProjProposalProj
                join projProposalJourds
              where  PSAProjProposalProj.ProjProposalId ==projProposalJourds.ProposalId
            {
                if( PSAProjProposalProj.InvoicedNow <= 0)
                {
                    //formDatasource.object(methodStr(ProjProposalJour,editReasonCode)).mandatory(projParameters.DTReasonCodeMandatory);
                    //formDatasource.object(fieldNum(ProjProposalJour, PaymMode)).mandatory(projParameters.DTOriginalInvoiceMandatory);
    
                    if(projParameters.DTOriginalInvoiceMandatory == NoYes::Yes && projProposalJourds.PaymMode == '')
                    {
                        throw error("The  method of  payment  field is mandatory. Cannot proceed further.");
                    }
    
                    if(projParameters.DTReasonCodeMandatory == NoYes::Yes && ReasonCode == null)
                    {
                        throw error("The Reason Code field is mandatory. Cannot proceed further.");
                    }
                }
            }
            next clicked();
    
        }*/
    
    }
    3)Code on work flow submit button 
    
    To trigger the error on submit button need to do code on main method of this class .
    [ExtensionOf(classStr(PSAProjInvoiceProposalSubmitToWF))]
    final class DTPSAProjInvoiceProposalSubmitToWF_Extension
    {
       //  Description    : test if the invoice proposal can be submitted to workflow
       public static void main(Args _args)
        {
            RecID                   recID               = _args.record().RecId;
            TableId                 tableId             = _args.record().TableId;
            ProjProposalJour        projProposalJour    = _args.record();
            WorkflowWorkItemTable   workItem            = _args.caller().getActiveWorkflowWorkItem();
            WorkflowSubmitDialog    workflowSubmitDialog;
            WorkflowComment         wfComment;
            workflowTypeName        workflowTemplateName = workFlowTypeStr('PSAProjInvoiceProposal');
            PSAProjProposalProj     pSAProjProposalProj;
            ReasonTableRef          reasonTableRef;
            ProjParameters          projParameters;
    
           
            // The method has not been called correctly.
            if (tableId != tablenum(ProjProposalJour) ||
                recId == 0)
            {
                throw error(strfmt("@SYS19306", funcname()));
            }
    
            if (projProposalJour.RecId != 0)
            {
                while select InvoicedNow from pSAProjProposalProj
                where  pSAProjProposalProj.ProjProposalId ==  projProposalJour.ProposalId
                {
                    select firstonly projParameters
                            where  projParameters.DataAreaId == projProposalJour.DataAreaId;
    
                    if( PSAProjProposalProj.InvoicedNow <= 0)
                    {
                        select Reason,RecId from   reasonTableRef
                                where   reasonTableRef.RecId ==  projProposalJour.ReasonTableRef;
    
                        if(projParameters.DTOriginalInvoiceMandatory == NoYes::Yes &&  projProposalJour.DTOriginalTaxInvoiceNo == ''
                                && projParameters.DTReasonCodeMandatory == NoYes::Yes && ReasonTableRef.Reason == '')
                        {
                            throw error("The Original Invoice field & Reason Code field is mandatory. Cannot proceed further.");
                            //ret = ret && false;
                        }
                        else if(projParameters.DTOriginalInvoiceMandatory == NoYes::Yes &&  projProposalJour.DTOriginalTaxInvoiceNo == '')
                        {
                            throw error("The Original Invoice field is mandatory. Cannot proceed further.");
                            //ret = ret && false;
                        }
                        else if(projParameters.DTReasonCodeMandatory == NoYes::Yes && ReasonTableRef.Reason == '')
                        {
                            throw error("The Reason Code field is mandatory. Cannot proceed further.");
                            //ret = ret && false;
                        }
                      
                    }
                }
    
            }
    
            // Make the form refresh its common workflow UI controls.
            PSAProjInvoiceProposalSubmitToWF::refreshCaller(_args);
            next Main(_args);
        }
    
    }
    
     
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    multiselect lookup on form contrl
    Below is my code please let me know where i am getting wrong , 
    [ExtensionOf(formStr(ProdTableCreate))]
    final class DTProductionOrderCreate_FormLookup_Extension
    {
        public void init()
        {
            next init();
            FormStringControl prodGroupControl = this.design().controlName(formControlStr(ProdTableCreate, ProdTable_DTSalesId));
            prodGroupControl.registerOverrideMethod(methodStr(FormDataObject, lookup), formMethodStr(ProdTableCreate, overridenCustGroupLookup));
    
        }
    
        public void overridenCustGroupLookup(FormStringControl _formControl)
        {
            QueryBuildDataSource qbds,qbds1;
            Query query = new Query();
            qbds = query.addDataSource(tableNum(SalesTable));
            qbds.addGroupByAndSelectionField(fieldNum(SalesTable, SalesId));
            TableId multiSelectTableNum = tableNum(SalesTable);
            container selectedFields = [multiSelectTableNum, fieldName2id(multiSelectTableNum, fieldStr(SalesTable, SalesId))];
            //MultiSelectInvoices.text(con2Str(SysLookupMultiSelectCtrl::constructWithQuery(element, this, query, false, selectedFields).getSelectedFieldValues(),';'));
            SysLookupMultiSelectGrid    lookupMS = new SysLookupMultiSelectGrid();
            lookupMS.parmCallingControl(_formControl);
            lookupMS.parmCallingControlId(_formControl);
            lookupMS.parmCallingControlStr(_formControl);
            lookupMS.parmQuery(query);
            //lookupMS.parmQueryRun(_queryRun);
            lookupMS.parmSelectField(selectedFields);
            lookupMS.run();
            container CarrierTypeCon = str2con(ProdTable_DTSalesId.text(),";");
            ProdTable_ds.object(fieldNum(ProdTable,DTSalesId)).setValue(con2Str(CarrierTypeCon, " ,"));
    
        }
    
    }
    thanks ,
    Regards,
    Dinesh

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,914 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,549 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans