Grabbiing Assigned User Email and Phone

CRM 7.1g

Hello All,

I created two fields in the leads module, assigned user email and phone, so that when their info can be added to the email template. The goal is to have the ability to send a mass email to all leads and have the contact info of the assigned user and not the person sending the email. I add table level script into the leads module but when I implement this, I am not able to open leads anymore. CRM just sits there loading the lead and I am not sure why. Here is the script below.


function PostInsertRecord()

{
var assigneduser = CRM.GetContextInfo('Lead','lead_assigneduserid');
var Query = CRM.CreateQueryObj("select * from users where user_userid = '"+assigneduser+"'");
Query.SelectSql();
while (!Query.eof){
Values("lead_assignedphone") = Query.FieldValue("user_phone");
Values("lead_assigneduseremail") = Query.FieldValue("user_emailaddress");
}
}


function UpdateRecord()

{
var assigneduser = CRM.GetContextInfo('Lead','lead_assigneduserid');
var Query = CRM.CreateQueryObj("select * from users where user_userid = '"+assigneduser+"'");
Query.SelectSql();
while (!Query.eof){
Values("lead_assignedphone") = Query.FieldValue("user_phone");
Values("lead_assigneduseremail") = Query.FieldValue("user_emailaddress");
}
}


  • 0

    Dear Jonathan,

    From your above post, I understand that you are trying to retrieve Lead assigned user’s Email address and Phone. On verifying your code, I found that you have used WHILE condition to retrieve the details but you have not mentioned Query.NextRecord(); function due to which it will execute endlessly and it slows down the CRM. As you are fetching a record for Lead assigned user then you can use IF condition instead of WHILE condition in Update function for the same.

    Regards,
    Dinesh

  • 0

    Thanks for your response.After I posted this, if change the while to if and it worked. Don't know why I didn't see that before.