This topic contains 2 replies, has 0 voices, and was last updated by JacksonP 7 years, 8 months ago.

  • Author
    Posts
  • #1055

    JacksonP

    I’ve got a scheduled script that runs daily at midnight, It creates a task for each customer result of a search. I’m setting the ‘sendemail’ field to false, and when I look at the task record. It does set the checkbox to unchecked. However the task is still sending the email to the sales rep. Has anyone run into this issue? Is there something I’m missing? Here is my code of creating a task:

    Code:
    var taskRec = record.create({
    type: record.Type.TASK,
    isDynamic: true,
    defaultValues: {
    customform: 72
    }
    });

    taskRec.setValue({
    fieldId: ‘title’,
    value: ‘SO Follow Up Task’
    });

    taskRec.setValue({
    fieldId: ‘company’,
    value: customerId
    });

    taskRec.setValue({
    fieldId: ‘sendemail’,
    value: false
    });

    taskRec.setValue({
    fieldId: ‘status’,
    value: ‘NOTSTART’
    });

    taskRec.setValue({
    fieldId: ‘custevent12’,
    value: 22
    });

    var lookupFields = search.lookupFields({
    type : ‘customer’,
    id : customerId,
    columns : [‘salesrep’, ’email’, ‘phone’]
    });

    var salesRep = lookupFields.salesrep[0].value;
    var email = lookupFields.email;
    var phone = lookupFields.phone;

    taskRec.setValue({
    fieldId: ‘assigned’,
    value: salesRep
    });
    taskRec.setValue({
    fieldId: ‘custevent8’,
    value: email
    });
    taskRec.setValue({
    fieldId: ‘custevent7’,
    value: phone
    });

    taskRec.save();
    This is a cached copy. Click here to see the original post.

  • #1056

    erictgrubaugh

    The problem you’re seeing is because you are working in Dynamic mode. This makes the code behave like you are interacting with the record in the UI, so the order in which you set fields matters.

    In the UI, when you change the Assignee, the “Notify Assignee by Email” field defaults to true. Your script is going to follow that same behaviour because the record is in Dynamic mode.

    You are first clearing the `sendemail` field, then changing the Assignee, which is re-checking the `sendemail` field. Either do not create the record in Dynamic mode, or if you must work in Dynamic mode, then wait to uncheck `sendemail` until after you have set the Assignee.

  • #1057

    JacksonP

    Ahh, okay missed that. Thanks Erictgrubaugh!

You must be logged in to reply to this topic.