Announcement

Collapse
No announcement yet.

Transferring Lead Stream Data to Opportunity with Original Attributes

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transferring Lead Stream Data to Opportunity with Original Attributes

    have successfully converted leads into contacts and opportunities. Now, what I am looking to achieve is the following:

    Is it possible to duplicate the stream data from the lead to the opportunity while retaining the original posting date and the users who created the posts? To elaborate, imagine we have more than 20 streams of data within a lead. Once the lead has been transformed into an opportunity, my goal is to replicate or transfer the stream data into the opportunity records, ensuring that the creation dates and user attributions remain consistent.

    If such functionality exists, I am eager to understand how this can be accomplished. Your guidance on the steps to achieve this would be greatly appreciated. Thank you for your assistance.

    Best regards,

  • #2
    Hi sapyantuk,

    In this case, you need to create a Workflow with:
    • Target Entity​: Lead
    • Trigger Type: After record updated​
    • Conditions:

      Click image for larger version  Name:	image.png Views:	0 Size:	8.7 KB ID:	97604
    • Actions: Execute Formula Script
    Code:
    $leadId = workflow\targetEntity\attribute('id');
    $opportunityId = workflow\targetEntity\attribute('createdOpportunityId');
    $opportunityName = workflow\targetEntity\attribute('createdOpportunityName');
    
    $notesIds = record\findMany('Note', 10000, 'createdAt', 'asc', 'parentId=', $leadId, 'type=', 'Post');
    
    $notesCount = array\length($notesIds);
    
    $i = 0;
    
    while(
        
        $i < $notesCount,
        
        (
            $noteId = array\at($notesIds, $i);
            $noteCreatedAt = datetime\format(record\attribute('Note', $noteId, 'createdAt'), 'Europe/Kiev');
            $notePost = record\attribute('Note', $noteId, 'post');
            $noteCreatedById = record\attribute('Note', $noteId, 'createdById');
            $noteCreatedByName = record\attribute('Note', $noteId, 'createdByName');
            
            // posts for converted opportunity creating
            
            $noteForOpportunityId = record\create(
                'Note',
                'post', string\concatenate($noteCreatedAt, '\n\n', $notePost),
                'type', 'Post',
                'parentId', $opportunityId,
                'parentType', 'Opportunity',
                'parentName', $opportunityName,
                'createdById', $noteCreatedById,
                'createdByName', $noteCreatedByName,
                );
                
            // attachments for new posts creating
            
            $noteAttachmentsIds = record\attribute('Note', $noteId, 'attachmentsIds');
            $newAttachmentsIds = list();
            
            $j = 0;
    
            while(
                
                $j < array\length($noteAttachmentsIds),
    
                (
                    $noteAttachmentId = array\at($noteAttachmentsIds, $j);
                    $newAttachmentsIds = array\push(
                        $newAttachmentsIds,
                        record\create(
                            'Attachment',
                            'role', 'Attachment',
                            'type', record\attribute('Attachment', $noteAttachmentId, 'type'),
                            'size', record\attribute('Attachment', $noteAttachmentId, 'size'),
                            'global', record\attribute('Attachment', $noteAttachmentId, 'global'),
                            'name', record\attribute('Attachment', $noteAttachmentId, 'name'),
                            'sourceId', $noteAttachmentId,
                            'storage', record\attribute('Attachment', $noteAttachmentId, 'storage'),
                            'field', 'attachments',
                            'parentId', $noteForOpportunityId,
                            'parentType', 'Note'
                        )
                        );
            $j = $j + 1;
            )
            );
            
            $i = $i + 1;
        )
    );​
    Last edited by lazovic; 09-19-2023, 08:06 AM.

    Comment

    Working...
    X