Skip to main content

Notifications

Announcements

No record found.

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

to pass the default value in init value of form

Posted on by 1,457
hi,
everyone,
I have customise form in which there is grid i need to increment the sqeuence number in grid so i have use the init value method , but my saquence no is not getting incremented ,
can anyone please help me on this .the line number is appearing 0, i want it to increment , please guide me on this .
 
thanks,
Regards,
Dinesh
  • Waed Ayyad Profile Picture
    Waed Ayyad 6,332 Super User 2024 Season 2 on at
    to pass the default value in init value of form
    Hi,
     
    If your issue is resolved, mark the correct answer as verified answer.
     
    Thanks,
    Waed Ayyad
  • Verified answer
    Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    to pass the default value in init value of form
    hi ,
    Thanks for reply invoice i was index filed thats why i was not getting the error on save i removed that now i am , now number are incrementing with code.
     
     
    thanks,
    Regards
    Dinesh
  • Suggested answer
    Nisha Soni 2709 Profile Picture
    Nisha Soni 2709 60 on at
    to pass the default value in init value of form
    Create number sequenece and attach it with that field.
  • Martin Dráb Profile Picture
    Martin Dráb 230,198 Most Valuable Professional on at
    to pass the default value in init value of form
    It seems that you're trying to save a record with values of a unique key that already exist.
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    to pass the default value in init value of form
    hi ,
    thanks for reply ,
     
    I have made changes in code on form line datasource i have written this code .
      public void initValue()
            {
     
                DTDMCHeaderLines.InvoiceDate = DTDMCHeader.InvoiceDate;
                DTDMCHeaderLines.inventLocationId = DTDMCHeader.inventLocationId; 
                super();
            }
    and on table i have override this method which gets vaslue from form dsmethod .
     public void initValue()
        {
            super();
    
            DTDMCHeaderLines   dTDMCHeaderLines;
            //Info(strFmt("InvoiceDate:%1,inventLocationId:%2",this.inventLocationId,this.InvoiceDate));
    
            if(this.InvoiceDate != dateNull() && this.inventLocationId != '')
            {
                select firstonly Seqnum from dTDMCHeaderLines 
                    order by DTDMCHeaderLines.Seqnum  desc 
                    where dTDMCHeaderLines.InvoiceDate == this.InvoiceDate 
                    && dTDMCHeaderLines.inventLocationId == this.inventLocationId;
            
               // this.CustomerName    = CustTable::find(this.InvoiceAccount).name();
                this.Seqnum =  dTDMCHeaderLines.Seqnum + 1 ;
            }
    
        }
    the value get incremented on create button but when i click on save it trigger the error that cannot create record in dtdmcheaderlinestable the record already exist.
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    to pass the default value in init value of form
     i have , made some changes in code now try to debug it , let you know what i get.
      public void initValue()
            {
    
                DTDMCHeaderLines   dTDMCHeaderLinesloc;
                Info(strFmt("InvoiceDate:%1,inventLocationId:%2",DTDMCHeaderLines.InvoiceDate,DTDMCHeaderLines.inventLocationId));
    
                //get any datasource from the base form      
                DTDMCHeader             dTDMCHeaderloc                  = DTDMCHeader_ds.Cursor();
              
                if(dTDMCHeaderloc.InvoiceDate != dateNull() && dTDMCHeaderloc.inventLocationId != '')
                {
                    select firstonly Seqnum from dTDMCHeaderLinesloc
                    order by DTDMCHeaderLinesloc.Seqnum  desc
                    where dTDMCHeaderLinesloc.InvoiceDate == dTDMCHeaderloc.InvoiceDate
                    && dTDMCHeaderLinesloc.inventLocationId == dTDMCHeaderloc.inventLocationId;
            
                
                  DTDMCHeaderLines.Seqnum =  dTDMCHeaderLinesloc.Seqnum + 1 ;
                }
                super();
            }
     
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    to pass the default value in init value of form
    hi , 
    how can i fetch the header in this method , you are right i am not getting the value in if , can you please guide me on this .do i have write the code on invit value of header , or should i keep it on line .
     
    thanks,
    Regards,
    Dinesh
  • Martin Dráb Profile Picture
    Martin Dráb 230,198 Most Valuable Professional on at
    to pass the default value in init value of form
    Let me remind you again that you have the debugger at your disposal, which will tell you what's going on in your code. You must learn how to use it to be able to do your job. As you see, guessing what's wrong doesn't work for you and using this forum instead of the debugger is very inefficient.
     
    Please put the breakpoint at if condition, run your project or attach the debugger to the web server and add a line. Tell us whether you get into the body of the if statement. I don't think so - your code will run only if InvoiceDate and InventLocationId fields have values, but that's not the case of a newly created record.
     
    I think you should take the values from the header, not from the line. The header must already exist when you're creating lines for it, but not no line exists before you create the first one.
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    to pass the default value in init value of form
    below is my code on form ds
       public void initValue()
            {
    
                DTDMCHeaderLines   dTDMCHeaderLinesloc;
                Info(strFmt("InvoiceDate:%1,inventLocationId:%2",DTDMCHeaderLines_inventLocationId,DTDMCHeaderLines_InvoiceDate));
    
                if(DTDMCHeaderLines.InvoiceDate != dateNull() && DTDMCHeaderLines.inventLocationId != '')
                {
                    select firstonly Seqnum from dTDMCHeaderLinesloc
                    order by DTDMCHeaderLinesloc.Seqnum  desc
                    where dTDMCHeaderLinesloc.InvoiceDate == DTDMCHeaderLines.InvoiceDate
                    && dTDMCHeaderLinesloc.inventLocationId == DTDMCHeaderLines.inventLocationId;
            
                  DTDMCHeaderLines.Seqnum =  dTDMCHeaderLinesloc.Seqnum + 1 ;
                }
                super();
            }
     

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans