handlers/kinetic_request_approval_create_v4/handler/init.rb
# Creates a KS_SRV_CustomerSuvey_base record with the 'Submit Type' of
# "Approval."  The purpose of this record is to invoke the Kinetic Request
# approval processing (see the README for more information).  The approval
# record is related to the original submission via the value of the
# 'Originating Id' field.
#
# This is a required method that is automatically called by the Kinetic Task
# Engine.
#
# ==== Returns
# An Xml formatted String representing the return variable results.
Creates a KS_SRV_CustomerSuvey_base record with the 'Submit Type' of
"Approval."  The purpose of this record is to invoke the Kinetic Request
approval processing .  The approval
record is related to the original submission via the value of the
'Originating Id' field.

This is a required method that is automatically called by the Kinetic Task
Engine.

Returns
An Xml formatted String representing the return variable results.
Creates a KS_SRV_CustomerSuvey_base record with the ' Submit Type ' of " Approval . " The purpose of this record is to invoke the Kinetic Request approval processing . The approval record is related to the original submission via the value of the ' Originating Id ' field . This is a required method that is automatically called by the Kinetic Task Engine . Returns An Xml formatted String representing the return variable results .
def execute()
    submission = retrieve_submission(@parameters['lookup_id'],
      @fields_to_clone + @additional_fields)
    submission_values = submission.field_values.inject({}) do |hash, (field_id, field_value)|
      field_name = @@remedy_forms['KS_SRV_CustomerSurvey_base'].field_for(field_id).name
      @additional_fields.include?(field_name) ? hash : hash.merge!(field_name => field_value)
    end
    originating_submission = retrieve_submission(submission['OriginatingID'], 
      ['instanceId', 'CustomerSurveyID', 'Survey_Template_Name'])
    @field_values = submission_values.merge(@field_values)
    @field_values.merge!(
      'LookupValueId' => submission['instanceId'],
      'Form' => originating_submission['Survey_Template_Name'],
      'OriginatingID' => originating_submission['instanceId'],
      'OriginatingID_Display' => originating_submission['CustomerSurveyID']
    )
    @field_values['SurveyInstanceID'] = get_survey_template_id(
      @parameters['approval_template_name'], @parameters['approval_template_catalog_name'])
    if (@parameters['message_template_name'])
      @field_values['MessageTemplateInstanceID'] = get_message_template_id(
        @parameters['message_template_name'], @field_values['ApplicationName'])
    end
    puts(format_hash("Approval Record Field Values:", @field_values)) if @debug_logging_enabled
    entry = @@remedy_forms['KS_SRV_CustomerSurvey_base'].create_entry!(
      :field_values => @field_values,
      :fields       => ['instanceId']
    )
    results = <<-RESULTS
    <results>
      <result name="Instance Id">#{escape(entry['instanceId'])}</result>
    </results>
    RESULTS
    puts("Results: \n#{results}") if @debug_logging_enabled
    return results
  end
def execute ( ) submission = retrieve_submission ( @parameters [ 'lookup_id' ] , @fields_to_clone + @additional_fields ) submission_values = submission . field_values . inject ( { } ) do | hash , ( field_id , field_value ) | field_name = @@remedy_forms [ 'KS_SRV_CustomerSurvey_base' ] . field_for ( field_id ) . name @additional_fields . include? ( field_name ) ? hash : hash . merge! ( field_name => field_value ) end originating_submission = retrieve_submission ( submission [ 'OriginatingID' ] , [ 'instanceId' , 'CustomerSurveyID' , 'Survey_Template_Name' ] ) @field_values = submission_values . merge ( @field_values ) @field_values . merge! ( 'LookupValueId' => submission [ 'instanceId' ] , 'Form' => originating_submission [ 'Survey_Template_Name' ] , 'OriginatingID' => originating_submission [ 'instanceId' ] , 'OriginatingID_Display' => originating_submission [ 'CustomerSurveyID' ] ) @field_values [ 'SurveyInstanceID' ] = get_survey_template_id ( @parameters [ 'approval_template_name' ] , @parameters [ 'approval_template_catalog_name' ] ) if ( @parameters [ 'message_template_name' ] ) @field_values [ 'MessageTemplateInstanceID' ] = get_message_template_id ( @parameters [ 'message_template_name' ] , @field_values [ 'ApplicationName' ] ) end puts ( format_hash ( "Approval Record Field Values:" , @field_values ) ) if @debug_logging_enabled entry = @@remedy_forms [ 'KS_SRV_CustomerSurvey_base' ] . create_entry! ( :field_values => @field_values , :fields => [ 'instanceId' ] ) results = <<-RESULTS 
    <results>
      <result name="Instance Id"> #{ escape ( entry [ 'instanceId' ] ) } </result>
    </results>
     RESULTS puts ( "Results: \n#{results}" ) if @debug_logging_enabled return results end
Creates a KS_SRV_CustomerSuvey_base record with the 'Submit Type' of
"Approval."
Creates a KS_SRV_CustomerSuvey_base record with the ' Submit Type ' of " Approval . "
# Retrieve the initial field values from the triggering base record.  These # will be copied into the approval record so that the data submitted by the # original submission can be used within the approval. # Initialize the Hash of field values based on the retrieved request record. # This builds a Hash that maps the KS_SRV_CustomerSurey_base database field # name to its values (and skips fields that should not be mapped, such as # 'Request Id' and 'instanceId'). # Determine the database name of the associated field # Add the field name to value map unless the field was specified in the # @additional_fields attribute (this prevents the duplicating of instance # id and request id). # Retrieve the originating submission so that we can manually populate the # originating id values.  This is necessary since Kinetic Request does not # set the OriginatingID or OriginatingID_Display on the originating record # itself, so these are not populated in the submission to be approved. # Merge the originating request values with the field values specified as # parameters (such as the Message Template and Approval Template).  This # gives precedence to the field values specified by the node.xml mapping. # Merge in the specified lookup Ids.  These are used to relate the approval # record to the originating record. # * Form (labeled as Originating Form) - This field is used to hold the name #   of the originating service item. # * LookupValueId - The instance id of the Kinetic Request submission that #   the approval is being created for.  This is different from the #   OriginatingID only when doing nested approvals. # * OriginatingID - The instance id of the original Kinetic Request #   submission. # * OriginatingID_Display - The request id of the original Kinetic Request #   submission. # Use the Approval Template Name and Approval Template Catalog Name # parameters to retrieve and add the SurveyInstanceID to the @field_values # hash. # Use the Message Template Name parameter to retrieve and add the # MessageTemplateInstanceID to the @field_values hash. # Log the field value map (if debug logging is enabled) # Create the KS_SRV_CustomerSurvey_base record using the @field_values hash # that was built up.  Pass 'instanceId' is passed to the fields argument to # explicitely specify the field values to return (this improves performance # over retrieving all fields on the submission record). # Build the results xml that will be returned by this handler. # Return the results String