Modifying field values

This topic provides examples of how to use additional attributes of the map tag to modify field values.

These additional attributes are supported:

  • from_field: Replaces the field with the value in the specified field name.
  • percent: If the field is numeric, applies the specified percent operation to the value in the field.
  • divide: If the field is numeric, applies the specified divide operation to the value in the field.
  • multiple: If the field is numeric, applies the specified multiple operation to the value in the field.
  • null: If the field is null after the mapping logic is applied, assigns the specified value to the field.

Example 1: Replace EARN_CODE with value in RETRO field

In this example, the value of the EARN_CODE field is replaced with the value in the RETRO field.

This is the full XML definition:

<payroll_export plugin="com.workbrain.app.export.payroll.basic.BasicPayrollExportPlugin"> 
    
  <data>
    <field name='emp_name'/>
    <field name='wrkd_minutes'/>
    <field name='tcode_name'/>
    <field name='htype_name'/>
    <field name='wrks_authorized'/>
    <field name='retro'/>
    <dummy_field name='earn_code'/>
  </data>

  <logic>
    <match_output>
      <match field="wrks_authorized" value="Y" />
      <match field="tcode_name" value="%" />
      <match field="htype_name" value="REG" />
      <output_row>
        <map field="earn_code" from_field="retro"  />
      </output_row >
    </match_output>

    <match_output>
      <match field="wrks_authorized" value="Y" />
      <match field="tcode_name" value="%" />
      <match field="htype_name" value="OT1.0" />
      <output_row>
        <map field="earn_code" from_field="retro" />
      </output_row >
    </match_output>
	
    <match_output>
      <match field="wrks_authorized" value="Y" />
      <match field="tcode_name" value="%" />
      <match field="htype_name" value="OT1.5" />
      <output_row>
        <map field="earn_code" from_field="retro" />
      </output_row >
    </match_output>

    <match_output>
      <match field="wrks_authorized" value="Y" />
      <match field="tcode_name" value="%" />
      <match field="htype_name" value="OT2.0" />
      <output_row>
        <map field="earn_code" from_field="retro" />
      </output_row >
    </match_output>

    <match_output>
      <match field="tcode_name" value="UAT" />
      <match field="htype_name" value="UNPAID" />
    </match_output>

    <match_output>
      <output_row>
        <map field="earn_code" from_field="retro"  />
      </output_row >
    </match_output>
  </logic>

  <format>
    <header>      
    </header>

    <body>
      <string field='emp_name' />
      <constant>,</constant>
      <string field='earn_code'/>
      <constant>,</constant>
      <number field='wrkd_minutes' format='########0.00' divide='60' null='***'/>
      <constant>,</constant>
      <string field='retro' />
      <new_line/>
    </body>
        
    <footer>           
    </footer>
  </format>

</payroll_export>

This table shows a sample of the Payroll Export file output:

emp_name earn_code wrkd_minutes retro
4224 N 8.00 N
4224 N 8.00 N
4224 N 8.00 N
4224 N 8.00 N
4224 N 8.00 N
4224 N 8.00 N
4224 N 8.00 N
4285 N 8.00 N
4285 N 8.00 N
4285 N 8.00 N
4285 N 8.00 N
4285 N 8.00 N
4285 N 8.00 N
4285 N 8.00 N

Example 2: Apply percent operation to EARN_CODE value

In this example, the percent operation is applied to the value of the EARN_CODE field.

This is the full XML definition:

<payroll_export plugin="com.workbrain.app.export.payroll.basic.BasicPayrollExportPlugin"> 

  <data>
    <field name='emp_name'/>
    <field name='wrkd_minutes'/>
    <field name='tcode_name'/>
    <field name='htype_name'/>
    <field name='wrks_authorized'/>
    <field name='retro'/>
    <dummy_field name='earn_code'/>
    <dummy_field name='nothing_blank'/>
   </data>

  <logic>
    <match_output>
      <match field="wrks_authorized" value="Y" />
      <match field="tcode_name" value="%" />
      <match field="htype_name" value="REG" />
      <output_row>
        <map field="earn_code" value="1"  />
	   <map field="earn_code" percent="5"  />
      </output_row >
    </match_output>

    <match_output>
      <match field="wrks_authorized" value="Y" />
      <match field="tcode_name" value="%" />
      <match field="htype_name" value="OT1.0" />
      <output_row>
        <map field="earn_code" value="4" />
        <map field="earn_code" percent="5" />
      </output_row>
    </match_output>
	
    <match_output>
      <match field="wrks_authorized" value="Y" />
      <match field="tcode_name" value="%" />
      <match field="htype_name" value="OT1.5"/>
      <output_row>
        <map field="earn_code" value="2" />
        <map field="earn_code" percent="5" />
      </output_row >
   </match_output>

    <match_output>
      <match field="wrks_authorized" value="Y" />
      <match field="tcode_name" value="%" />
      <match field="htype_name" value="OT2.0" />
      <output_row>
        <map field="earn_code" value="5" />
        <map field="earn_code" percent="5" />
      </output_row >
    </match_output>

    <match_output>
      <match field="tcode_name" value="UAT" />
      <match field="htype_name" value="UNPAID" />
    </match_output>

    <match_output>
      <output_row>
        <map field="earn_code" value="E" />
      </output_row >
    </match_output>
  </logic>

  <format>
    <header>
    </header>
        
    <body>
      <string field='emp_name' />
      <constant>,</constant>
      <string field='earn_code'/>
      <constant>,</constant>
      <number field='wrkd_minutes' format='########0.00' divide='60' null='***'/>
      <constant>,</constant>
      <string field='retro' />
      <new_line/>
    </body>
        
    <footer>
    </footer>
  </format>

</payroll_export>

This table shows a sample of the Payroll Export file output:

emp_name earn_code wrkd_minutes retro
4213 0.05 8.00 N
4213 0.05 8.00 N
4213 0.05 8.00 N
4213 0.05 8.00 N
4213 0.05 8.00 N
4213 0.05 8.00 N
4213 0.05 8.00 N
4229 0.05 8.00 N
4229 0.05 8.00 N
4229 0.05 8.00 N
4229 0.05 8.00 N
4229 0.05 8.00 N
4229 0.05 8.00 N
4229 0.05 8.00 N

Example 3: Replace EARN_CODE value with "*" if value is null

In this example, the value of the EARN_CODE field is replaced with "*" if value is null.

This is the full XML definition:

<payroll_export plugin="com.workbrain.app.export.payroll.basic.BasicPayrollExportPlugin"> 

  <data>
    <field name='emp_name'/>
    <field name='wrkd_minutes'/>
    <field name='tcode_name'/>
    <field name='htype_name'/>
    <field name='wrks_authorized'/>
    <field name='retro'/>
    <dummy_field name='earn_code'/>
    <dummy_field name='nothing_blank'/>
  </data>

  <logic>
    <match_output>
      <match field="wrks_authorized" value="Y" />
      <match field="tcode_name" value="%" />
      <match field="htype_name" value="REG" />
      <output_row>
        <map field="earn_code" value="" />
        <map field="earn_code" null="*" />
      </output_row >
    </match_output>

    <match_output>
      <match field="wrks_authorized" value="Y" />
      <match field="tcode_name" value="%" />
      <match field="htype_name" value="OT1.0" />
      <output_row>
        <map field="earn_code" value="4"  />
       </output_row >
     </match_output>
	
    <match_output>
      <match field="wrks_authorized" value="Y" />
      <match field="tcode_name" value="%" />
      <match field="htype_name" value="OT1.5" />
      <output_row>
        <map field="earn_code" value="2" />
      </output_row >
    </match_output>

    <match_output>
      <match field="wrks_authorized" value="Y" />
      <match field="tcode_name" value="%" />
      <match field="htype_name" value="OT2.0" />
      <output_row>
        <map field="earn_code" value="5" />
      </output_row >
    </match_output>

    <match_output>
      <match field="tcode_name" value="UAT" />
      <match field="htype_name" value="UNPAID" />
    </match_output>

    <match_output>
      <output_row>
        <map field="earn_code" value="E"  />
      </output_row >
    </match_output>
  </logic>

  <format>
    <header>      
    </header>

    <body>
      <string field='emp_name' />
      <constant>,</constant>
      <string field='earn_code'/>
      <constant>,</constant>
      <number field='wrkd_minutes' format='########0.00' divide='60' null='***'/>
      <constant>,</constant>
      <string field='retro' />
      <new_line/>
    </body>
    
    <footer>
     
    </footer>
  </format>

</payroll_export>

This table shows a sample of the Payroll Export file output:

emp_name earn_code wrkd_minutes retro
4222 * 8.00 N
4222 * 8.00 N
4222 * 8.00 N
4222 * 8.00 N
4222 * 8.00 N
4222 * 8.00 N
4222 * 8.00 N
4248 * 8.00 N
4248 * 8.00 N
4248 * 8.00 N
4248 * 8.00 N
4248 * 8.00 N
4248 * 8.00 N
4248 * 8.00 N