Cloud Formula: Create a Meeting when Opportunity is created

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • crmclients
    Senior Member
    • Jul 2020
    • 280

    #1

    Cloud Formula: Create a Meeting when Opportunity is created

    Hi All

    Alternative to Workflow: I thought I would post this request that came out of a client need. We are repurposing Opps for Events with $$$ needing to be tracking, Modeling for now, may build custom in the future but since all the reports are there etc. Opportunities however don't show up on the Calendar, of course, that would be way too cluttered, but since she will have approximately 4 a month, I thought to create a corresponding meeting that does show up.

    Put this in the Opportunity Entity Formula, Before Save Custom Script option

    Operation:
    -Create opportunity, Save
    -Meeting is created with Opp Due Date and copies Opp name
    -Change Opp Due Date
    -Meeting Date is updated and on the Calendar, moved to the new date

    I would love to claim credit for the code but alas, I had help from Claude.ai Note, this creates a Meeting at 12/Noon for Pacific Time, update the 19 hours to whatever you need to for your time zone

    ================================================== ===========================
    // Formula to create or update a Meeting when an Opportunity is saved
    // Place this in the Opportunity entity's Formula section


    // Check if this is an update and if closeDate has changed
    $isUpdate = !entity\isNew();
    $closeDateChanged = $isUpdate && entity\isAttributeChanged('closeDate');

    // Only proceed if it's a new record OR if closeDate was changed
    ifThen(
    entity\isNew() || $closeDateChanged,

    // Convert closeDate to datetime at noon Pacific Time (12:00 PM PT)
    // Adding 19 hours (12 for noon + 7 for UTC offset) to get noon Pacific

    $meetingDateTime = datetime\addHours(
    datetime\format(closeDate, 'Y-m-d 00:00:00'),
    19

    );

    // If it's an update with closeDate change, find and update existing meeting
    ifThenElse(
    $closeDateChanged,

    // UPDATE EXISTING MEETING
    $existingMeetingId = record\findOne(
    'Meeting',
    'parentType', 'Opportunity',
    'parentId', id,
    'status', list('Planned', 'Not Started') // Only update meetings that haven't been held yet
    );

    // If existing meeting found, update it
    ifThen(
    $existingMeetingId,
    record\update(
    'Meeting',
    $existingMeetingId,
    'name', string\concatenate('Meeting for ', name),
    'dateStart', $meetingDateTime,
    'dateEnd', datetime\addHours($meetingDateTime, 1),
    'description', string\concatenate('Follow-up meeting for opportunity: ', name, ' (Updated)')
    )
    );

    // If no existing meeting found, create new one
    ifThen(
    !$existingMeetingId,
    $meetingId = record\create(
    'Meeting',
    'name', string\concatenate('Meeting for ', name),
    'status', 'Planned',
    'dateStart', $meetingDateTime,
    'dateEnd', datetime\addHours($meetingDateTime, 1),
    'parentType', 'Opportunity',
    'parentId', id,
    'assignedUserId', '68491c1b4d1768163',
    'usersIds', list('6849186677e472c15'),
    'description', string\concatenate('Follow-up meeting for opportunity: ', name)
    )
    ),

    // CREATE NEW MEETING (for new opportunities)
    $meetingId = record\create(
    'Meeting',
    'name', string\concatenate('Meeting for ', name),
    'status', 'Planned',
    'dateStart', $meetingDateTime,
    'dateEnd', datetime\addHours($meetingDateTime, 1),
    'parentType', 'Opportunity',
    'parentId', id,
    'assignedUserId', '68491c1b4d1768163',
    'usersIds', list('6849186677e472c15'),
    'description', string\concatenate('Follow-up meeting for opportunity: ', name)
    )
    )
    );

    ---------------------------------------------------------------------------------------------------------------------------
    Have fun!
Working...