I have a requirement that while inserting Customer (f3) we need to open the Data Template List (Form 8620) and user will select the required Data template for updating the Customer Fields based on the data template setup.
So i inserted the below code in Customer table oninsert trigger
RecRef.GETTABLE(Rec);
TemplateMgt.UpdateFromTemplateSelection(RecRef);
where RecRef is a recordref global variable and TemplateMgt is golbal variable for Codeunit 8612 (Template Management).
when i try to insert new customer record, the Data template list is opening and after selecting the required template, it is showing error as "Customer No. does not exists" etc... I have not done any other customizations other than this 2 lines of code.
Has anyone already worked on this type of requirement? Your valuable suggetsion are highly appreciated.
Thanks in advance.
0
Answers
Try using COMMIT just before your code, so it works like the standard: first the customer is created (and commited) and then a template is applied.
Salut!
Laura Nicolàs
Author of the book Implementing Dynamics NAV 2013
Cursos Dynamics NAV (spanish) : http://clipdynamics.com/ - A new lesson released every day.
Thanks for your reply.
Already, I tried using COMMIT before my codes but the result is same (still getting the same errors)
Yes, i have placed my coding at the end of Oninsert trigger.
COMMIT at that point is definitely no good programming. Wouldn't it be easier if you create a contact first and than use the function Create As -> Customer? In this way you can apply a template by standard.
That's the reason why he is getting the error "The customer does not exist" and that's the reason why I proposed to use COMMIT. Only if the new code was placed at the end of the trigger, so if an error occurs before this, the transaction is not commited.
Salut!
Laura Nicolàs
Author of the book Implementing Dynamics NAV 2013
Cursos Dynamics NAV (spanish) : http://clipdynamics.com/ - A new lesson released every day.
P.S.: einstein solution IS the easiest way to proceed, anyway
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog
I tried to use COMMIT on the OnInsert trigger... and it is not working. The transaction does not get commited because an error occurs on the trigger... even if it occurs AFTER the commit sentence.
I thought COMMIT worked always... so thanks for the tip!
Salut!
Laura Nicolàs
Author of the book Implementing Dynamics NAV 2013
Cursos Dynamics NAV (spanish) : http://clipdynamics.com/ - A new lesson released every day.
As you know, in Customer Card we can apply template using Functions -> Apply Template. In my case, customer doesn't want to click (and even do any other actions) the function to select templates . Customer needs this template has to be listed after inserting the Customer No. (Customer No. are inserted using No. Series) and then they will select the required one.
Thats why i asked is there any other possibilities to complete this requirement.
well, i think that if the user presses f3, then arrowdown to validate the no. and this will pop up the template list it would be not so bad...am i missing something in your post?
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog
am i misunderstanding something in your post? :-k
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog
On the template form you have the button Functions -> Create Instance.
Take a look at the code to see how it works.
Salut!
Laura Nicolàs
Author of the book Implementing Dynamics NAV 2013
Cursos Dynamics NAV (spanish) : http://clipdynamics.com/ - A new lesson released every day.
Also, the Customer No's are inserted using No. Series (Default and NOT Manual) and therefore until some validation performed in "No." field, the "OnValidate" trigger will not be executed. As the requirement is while inserting Customer, the template has to be listed and from which user will select the required one and the customer fields has to updated accordingly.
Any other workarounds?
Create a function on the customer card called "create cust. from template", accessible from any free key combination. Tell users not to use the F3, but the new key you defined.
From that function write code to open the template form, let the user select the template and then call the function used on the standard "Create Instance" option.
Salut!
Laura Nicolàs
Author of the book Implementing Dynamics NAV 2013
Cursos Dynamics NAV (spanish) : http://clipdynamics.com/ - A new lesson released every day.
I am aware of this function but do you think changing the key in the Customer Card and asking the user not to use F3 for inserting record is good practice?
I proposed to create a new fucntion with a new ShortCutKey.
Salut!
Laura Nicolàs
Author of the book Implementing Dynamics NAV 2013
Cursos Dynamics NAV (spanish) : http://clipdynamics.com/ - A new lesson released every day.
Do something like
Codeunit.GetCustTemplate(Rec)
In the function GetCustTemplate have the Cust Parameter by VAR. Open the Template window and have the user select one. Update the fields of the parameter. You do not even need to run a modify on the parameter.
FD Consulting
Give it a try with the OnNewRecord-trigger of the form.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
Form - OnInsertRecord(BelowxRec : Boolean) : Boolean
RecInserted := TRUE;
Form - OnTimer()
IF RecInserted AND ("No." <> '') THEN BEGIN
RecRef.GETTABLE(Rec);
TemplateMgt.UpdateFromTemplateSelection(RecRef);
InsertRec := FALSE;
END;
Create a menuitem under Button Customer with Shortcut F3 (to intercept the F3 key). In that function you ask for the template and create a new customer-record and have the customer card form position on that new record before giving back control to the user.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
The problem with CU8612 and my solution is that CU8612 modifies the RecRef assuming that the record already exists. But in the OnNew Trigger of the form it does not.
Just to try comment the lien RecRef.modify. If it works create a Fu in CU8612 with a parameter NoModify and change the code so that the RecRef.modify is not executed if NoModify is true. As the RecRef is transferred to CU8612 by VAR and also in all Fu of CU8612 this should work.
FD Consulting
Dinh - The only problem i noticed that the fields in the customer are not updated immediately. Refreshing problem is there otherwise works well. If we go out of form and then reopen it again, then the values are updated else NOT.
Kriki - You idea works very well.
Thanks a lot guys for your answers. Have a nice weekend.
With my solution you can just add a CurrForm.UPDATE:
Form - OnTimer()
IF RecInserted AND ("No." <> '') THEN BEGIN
RecRef.GETTABLE(Rec);
TemplateMgt.UpdateFromTemplateSelection(RecRef);
InsertRec := FALSE;
CurrForm.UPDATE;
END;
Thanks a lot for your help .