handlers/kinetic_request_answer_update_v5/handler/init.rb
# The execute method takes no parameters and should leverage the instance
# variables setup and validated by the initialize method to generate a result
# xml string.
The execute method takes no parameters and should leverage the instance
variables setup and validated by the initialize method to generate a result
xml string.
The execute method takes no parameters and should leverage the instance variables setup and validated by the initialize method to generate a result xml string .
def execute()
	base_entry = get_base_record(@parameters['SubmissionInstanceID'])
    question_entry = get_question(@parameters['TemplateName'],@parameters['QuestionName'], base_entry['SurveyInstanceID'])
	@field_values['CustomerSurveyInstanceID'] = @parameters['SubmissionInstanceID']
    @field_values['QuestionInstanceID'] = question_entry['instanceId']
    @field_values['FullAnswer'] = @parameters['QuestionValue']
    @field_values['AnswerViewer'] = @parameters['QuestionValue'][0..254]
	unlimitedAnswer=false
	if @parameters['QuestionValue'].bytesize > 4000
		puts("Answer > 4000 bytes.") if @debug_logging_enabled
		unlimitedAnswer=true
		@field_values['FullAnswer'] = @parameters['QuestionValue'][0..3999]
		@field_values['UnlimitedAnswer'] = @parameters['QuestionValue']
	end
    if question_entry['Answer_MappingFieldID'] != nil
      field_id = question_entry['Answer_MappingFieldID']
      base_entry = get_base_record(@parameters['SubmissionInstanceID'])
      field_name = @@remedy_forms['KS_SRV_CustomerSurvey_base'].field_for(field_id.to_i).name
      base_entry.update_attributes!(field_name => @field_values['AnswerViewer'])
    end
    qual = %|'QuestionInstanceID' = "#{question_entry['instanceId']}" AND 'CustomerSurveyInstanceID' = "#{@parameters['SubmissionInstanceID']}"|
    @entry = @@remedy_forms['KS_SRV_SurveyAnswer'].find_entries(
      :single,
      :conditions => [qual],
      :fields => :all
      )
    if @entry.nil?
		puts("Did not find answer, Creating Answer.") if @debug_logging_enabled
      @entry = @@remedy_forms['KS_SRV_SurveyAnswer'].create_entry!(
      :field_values => @field_values
		)
	else
		puts("Found answer, Updating Answer.") if @debug_logging_enabled
		if (unlimitedAnswer)
			@entry.update_attributes!({'UnlimitedAnswer' =>  @field_values['UnlimitedAnswer'],'FullAnswer' =>  @field_values['FullAnswer'], 'AnswerViewer' => @field_values['AnswerViewer']})
		else
			@entry.update_attributes!({'FullAnswer' =>  @field_values['FullAnswer'], 'AnswerViewer' => @field_values['AnswerViewer']})
		end
	end
    results = <<-RESULTS
    <results>
      <result name="Value">#{escape(@entry['AnswerViewer'])}</result>
	  <result name="Entry Id">#{escape(@entry.id)}</result>
    </results>
    RESULTS
 end
def execute ( ) base_entry = get_base_record ( @parameters [ 'SubmissionInstanceID' ] ) question_entry = get_question ( @parameters [ 'TemplateName' ] , @parameters [ 'QuestionName' ] , base_entry [ 'SurveyInstanceID' ] ) @field_values [ 'CustomerSurveyInstanceID' ] = @parameters [ 'SubmissionInstanceID' ] @field_values [ 'QuestionInstanceID' ] = question_entry [ 'instanceId' ] @field_values [ 'FullAnswer' ] = @parameters [ 'QuestionValue' ] @field_values [ 'AnswerViewer' ] = @parameters [ 'QuestionValue' ] [ 0 .. 254 ] unlimitedAnswer = false if @parameters [ 'QuestionValue' ] . bytesize > 4000 puts ( "Answer > 4000 bytes." ) if @debug_logging_enabled unlimitedAnswer = true @field_values [ 'FullAnswer' ] = @parameters [ 'QuestionValue' ] [ 0 .. 3999 ] @field_values [ 'UnlimitedAnswer' ] = @parameters [ 'QuestionValue' ] end if question_entry [ 'Answer_MappingFieldID' ] != nil field_id = question_entry [ 'Answer_MappingFieldID' ] base_entry = get_base_record ( @parameters [ 'SubmissionInstanceID' ] ) field_name = @@remedy_forms [ 'KS_SRV_CustomerSurvey_base' ] . field_for ( field_id . to_i ) . name base_entry . update_attributes! ( field_name => @field_values [ 'AnswerViewer' ] ) end qual = %|'QuestionInstanceID' = "#{question_entry['instanceId']}" AND 'CustomerSurveyInstanceID' = "#{@parameters['SubmissionInstanceID']}"| @entry = @@remedy_forms [ 'KS_SRV_SurveyAnswer' ] . find_entries ( :single , :conditions => [ qual ] , :fields => :all ) if @entry . nil? puts ( "Did not find answer, Creating Answer." ) if @debug_logging_enabled @entry = @@remedy_forms [ 'KS_SRV_SurveyAnswer' ] . create_entry! ( :field_values => @field_values ) else puts ( "Found answer, Updating Answer." ) if @debug_logging_enabled if ( unlimitedAnswer ) @entry . update_attributes! ( { 'UnlimitedAnswer' => @field_values [ 'UnlimitedAnswer' ] , 'FullAnswer' => @field_values [ 'FullAnswer' ] , 'AnswerViewer' => @field_values [ 'AnswerViewer' ] } ) else @entry . update_attributes! ( { 'FullAnswer' => @field_values [ 'FullAnswer' ] , 'AnswerViewer' => @field_values [ 'AnswerViewer' ] } ) end end results = <<-RESULTS 
    <results>
      <result name="Value"> #{ escape ( @entry [ 'AnswerViewer' ] ) } </result>
	  <result name="Entry Id"> #{ escape ( @entry . id ) } </result>
    </results>
     RESULTS end
The execute method takes no parameters and should leverage the instance
variables setup and validated by the initialize method to generate a result
xml string.
The execute method takes no parameters and should leverage the instance variables setup and validated by the initialize method to generate a result xml string .
# Get the Question entry associated with the Question Name and Template Name # Set the field_values hash with the Question IID. # Update the originating request's Attributes if the Answer value is mapped. We know # it's mapped if there is a value in the Answer_FieldMappingID variable. # Convert the Mapping Field ID to the Field Name # Update the Base Entry's mapped Attribute. # Find and update the Answer entry.  # Return the results