Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Asif Malik 203 posts 339 karma points
    Mar 05, 2012 @ 10:17
    Asif Malik
    0

    Custom workflow

    I am trying to get a custom workflow working, which copies the values of one field to another field. The form is made up of 2 steps. On step one you can select from a list of available dates, and the idea is to show what you had selected on Step 2. The PartiallySubmitted does not appear to trigger a workflow, so i have been trying to work with the Resumed workflow (just to get the logic working). The problem i am facing is that when my workflow runs the data in the record is not current, i have also noticed that while my data does get saved (have checked the db) it then gets overwritten. It appears that the workflow is actually run before the record data has been updated, and then anything i do to the record gets overwritten. Maybe something in my code is worng, I would appreciate any help. Thanks. My code is below

    public override WorkflowExecutionStatus Execute ( Record record, RecordEventArgs e )
    {
        RecordField rfFrom = new RecordField ( );
        RecordField rfTo = null;
    
        foreach ( RecordField rf in record.RecordFields.Values )
        {
            if ( rf.Field.Id == new Guid ( FieldNameFrom ) )
                rfFrom = rf;
    
            if ( rf.Field.Id == new Guid ( FieldNameTo ) )
                rfTo = rf;
        }
    
        if ( rfTo == null )
        {
            var key = Guid.NewGuid ( );
    
            var rf = e.Form.AllFields.First ( item => item.Id == new Guid ( FieldNameTo ) );
    
            if ( rf != null )
            {
                rfTo = new RecordField ( )
                {
                    Field = rf,
                    Key = key,
                    Record = record.Id,
                    Values = rfFrom.Values
                };
    
                RecordFieldStorage rfs = new RecordFieldStorage ( );
                rfs.InsertRecordField ( rfTo );
                record.RecordFields.Add ( key, rfTo );
                rfs.Dispose ( );
            }
        }
        else
        {
            RecordFieldStorage rfs = new RecordFieldStorage ( );
            rfTo.Values = rfFrom.Values;
            rfs.UpdateRecordField ( rfTo );
            rfs.Dispose ( );
        }
    
        RecordStorage rs = new RecordStorage ( );
        rs.UpdateRecord ( record, e.Form );
        rs.UpdateRecordXml ( record, e.Form );
        rs.Dispose ( );
    
        return WorkflowExecutionStatus.Completed;
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft