function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
TMangoTMango 

Submitted By Field on Cases

We have a custom field in our case called Submitted By.  This field was originally built as Read Only, defaulting to the creator of the case.  However, this was causing workflow issues so we changed it to an editable field.  It is a lookup to the User Table, and the idea is to choose the name of the individual originating the request (often not the creator).  However, any time we choose a name from the table, it changes it back to the creators name.  It must be updated 2x before it will save.  Can anyone help with this?

symantecAPsymantecAP

There must be a workflow already running to this. check work flows on submitted by field

 

MandyKoolMandyKool

Hi,

 

Looks like your workflow is still activated...deactivate it and then check.

 

Thanks,

Kulkarni.

TMangoTMango

I will check workflows ... just as an FYI, this sometimes also happens on Case Ownership.  We often have to change the owner 2x before it will display correctly.  Would this also be a result of a workflow rule?

symantecAPsymantecAP

well yeah check the workflows it is assigned to. It might be there.

Prashant.SakhujaPrashant.Sakhuja

Workflow certainly could be updating the Submitted by and Owner fields. However if someone has written a trigger on the Case object that could also be the reason...

TMangoTMango

PRASHANT!  You are my hero!  I checked and checked the workflow, and couldn't find anything.  But when you mentioned the triggers, I checked and do see a couple of triggers that are built around Submitted By and Case Owner --- but I don't really know how to read them completely.  I've pasted below the triggers --- can you help me decipher exactly what they do (and maybe tell me why someone would build these)?

 

I still want the Submitted By field to default to the user name if it's blank --- but if it has something in it, I want it to not change ..... and as far as the Case Owner, I want it to accept the change the FIRST time .... :-)

 

TRIGGER: setAdditionalCaseInfo

 

trigger setAdditionalCaseInfo on Case (before Insert, before Update) {
    Set<Id> accountIdList=new Set<Id>();
    for(Case c:Trigger.New)
    {
        if(Trigger.IsInsert)
        {
            //set submiited by
            c.Submitted_By__c=UserInfo.getUserId();
            if(c.AccountId!=null)
            {
                accountIdList.add(c.AccountId);
            }
        }
        else
        {
            Case oldcase=Trigger.oldmap.get(c.Id);
            if(c.AccountId!=oldCase.AccountId && c.AccountId!=null)
            {
                accountIdList.add(c.AccountId);
            }
        }
    }
    if(accountIdList.size()>0)
    {
        //get Account Owner Information
        Map<Id, Account> accountmap=new Map<Id, Account>([Select Id, Owner.Name from account where Id in:accountIdList]); 
        for(Case c:Trigger.New)
        {
            if(Trigger.IsInsert)
            {                
                if(c.AccountId!=null)
                {
                    if(accountmap.get(c.AccountId)!=null)
                    {
                        c.Account_Owner__c=accountmap.get(c.AccountId).Owner.Name;
                    }
                }
            }
            else
            {
                Case oldcase=Trigger.oldmap.get(c.Id);
                if(c.AccountId!=oldCase.AccountId && c.AccountId!=null)
                {
                   if(accountmap.get(c.AccountId)!=null)
                   {
                       c.Account_Owner__c=accountmap.get(c.AccountId).Owner.Name;
                   }
                }
            }
        }
    }
}

 

 

TRIGGER: caseOwnerUpdate

 

trigger caseOwnerUpdate on Case (after update) {
    List<Case> updateCS = new List<Case>();
    Map<Id,Case> cases = new Map<Id,Case>();
    
    for (Case cs : Trigger.new)
    {
        if(Trigger.isUpdate) {  
            System.debug('>>>>> Owner ID: '+cs.ownerId+' Temp Owner ID: '+cs.TempOwnerId__c);
            if(cs.TempOwnerId__c <> null && cs.TempOwnerId__c <> '') {
                if(cs.OwnerId <> cs.TempOwnerId__c) {
                    cases.put(cs.id,cs);
                }
            }           
        }   
    }
    if (cases.isEmpty()) return;
    
    for (Case cs : [SELECT OwnerId,TempOwnerId__c FROM Case WHERE id in :cases.keySet()]) {
        cs.OwnerId = cases.get(cs.Id).TempOwnerId__c;
        cs.TempOwnerId__c = 'SKIP'; //flag to stop infinite loop upon update
        updateCS.add(cs);
    }
    System.debug('>>>>>Update Cases: '+updateCS);
    
    //
    //Update last assignment for Assignment Group in batch
    //
    if (updateCS.size()>0) {
        try {
            update updateCS;
        } catch (Exception e){

        }
    }

symantecAPsymantecAP

Hi Sarna

 

Yes this trigger changes the submitted by field to  current user.( c.Submitted_By__c=UserInfo.getUserId();)u can make a change in the trigger to get the id of the user who originates the request. 

For testing purpose deactivate the trigger and test it with workflow.

Let us knw if it works

 

TMangoTMango

Hi --- thanks for your help!  I'm not really familiar with triggers though --- so if you could assist, that would be great.  Here's what I would like to have happen:

 

1./  If the Submitted By field is left blank at the origination of the request (or is a read-only field), I would like the Submitted By field to automatically add the user name at save.

 

2./  If the Submitted By field is NOT left blank at the origination of the request, I would like the Submitted By field to NOT change from what it says to the user name automatically, as it does now.

 

Can this be accomplished?  Or is it an "all or nothing" deal? 

symantecAPsymantecAP

If I understand it correctly 

 

If submitted by field is blank it should be equal to the requestor

 

If it already has a value in there it shud nt change.

 

 

TMangoTMango

Yes ... can this trigger be changed to do that?

 

Also --- can you look at the Case Owner trigger and let me know why it would not accept the first Case Owner change (always defaults back)?