Dear folks, a few days ago I ask for my problem but now the situation has changed, so I'd like to post it in a new topic.
I've a report that has the Customer table as only Dataitem. I want that the report shows the e-mail contact person type that has as a job responsibility code "Accounting" department. This is the code that I put on customer OnAfterGetRecord:
BusRelation.RESET;
BusRelation.SETRANGE("Link to Table",BusRelation."Link to Table"::Customer);
BusRelation.SETRANGE("No.",Customer."No.");
jobrelation.RESET;
jobrelation.SETRANGE("Contact No.",BusRelation."No.");
IF BusRelation.FIND( '-' ) THEN;
contacto.SETRANGE("Company No.",BusRelation."Contact No.");
contacto.SETRANGE(Type, contacto.Type::Person);
jobrelation.SETRANGE("Job Responsibility Code",'Accounting');
IF contacto.FIND( '-' ) THEN REPEAT
UNTIL contacto.NEXT = 0;
BusRelation var is table Contactact Business Relation
contacto var is table Contact
jobrelation var es table Contact job Responsibility
The code runs well, but go to the contact person type from contact table from that customer, not from "Contact job Resposibility" table to get the e-mail from Accounting department. How can I do it?. As a second option, if that e-mail field can be moved to the customer table as a new field it also will be good to me.
Thanks for your valuable help.
Comments
Can you verify that you want to find the company contact first i.e.
Customer -> Business Relation -> Contact Type "Company"
then find a contact type "Person" associated with the Contact Type "Company" who has a Contact job Responsibility of 'Accounting'. If found then use the contact E-Mail address. Is this is correct then I will post the code for you.
Dynamics Nav Add-ons
http://www.simplydynamics.ie/Addons.html
Thank you.
The code you need on the onaftergetrecord of the customer is:
You will need to print the PersonContact."E-Mail" on the customer body section.
The message statement is just for testing and EMailFound is a variable of type Boolean.
Dynamics Nav Add-ons
http://www.simplydynamics.ie/Addons.html
Thanks for help.
Sorry I'm a bit confused. If you are going back to the company type contact then you already have got this in the contacto variable.
the sequence you are proposing is:
Is the origonal company contact not correct?
Dynamics Nav Add-ons
http://www.simplydynamics.ie/Addons.html
Thanks for help.
Thanks.
A Slight change should do as you want:
this gets all the person contact for a customer and returns the E-Mail from the first person with job responsibility 'DPTO. CONTABILIDAD'
Dynamics Nav Add-ons
http://www.simplydynamics.ie/Addons.html
The only problem is that if there is not a "CONTABILIDAD" department contact person, the report gets the first contact person from that company that finds. It would be nice if there is no one in the CONTABILIDAD department gets the mail from main contact or leave it in blank. Do you know how I can do it if it is not very complicated for you?.
Thank you very much for your help and time.
Good work
What I think you need is even simplier:
Glad to Help
Dynamics Nav Add-ons
http://www.simplydynamics.ie/Addons.html
Thanks again for help.