handlers/kinetic_request_attribute_create_v1/handler/init.rb
# Creates a record in the KS_SRV_Helper form
#
# 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 record in the KS_SRV_Helper form
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 record in the KS_SRV_Helper form 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()
	status=""
	error_code=""
	results_message=""
	@field_values = {}
	attribute_list = CSV.parse(@parameters['attribute_list'])
	attribute_array = attribute_list[0]
	@field_values['Record Status'] = "Active"
	@field_values['Status'] = "Active"
	@field_values['Application'] = "Kinetic Request"
	@field_values['ApplicationName'] = "Kinetic Request"
    csvfile = get_attachment(@parameters['customer_survey_instance_id'],@parameters['csv_file'], @parameters['survey_template_instance_id'])
	records=Base64.decode64(csvfile.base64_content).split(/\r?\n/)
	if records.length>0
		headerRow = records[0]
		@headers = CSV.parse(headerRow)
		survey_template_header_idx = @headers[0].index("Service Item Name")
		records.shift
	end
	puts "header row found: #{headerRow}" if @debug_logging_enabled
	puts "header 0: #{@headers[0][0]}" if @debug_logging_enabled
	puts "Service item name in index #{survey_template_header_idx}" if @debug_logging_enabled
	rowcount=0
	itemsNotFound=0
	attributesNotFound=0
	records.each do |record|
		recordArray = CSV.parse(record)
		inputArray = recordArray[0]
		puts "processing row found: #{inputArray}" if @debug_logging_enabled
		rowcount += 1
		column_num = 0
		survey_template_name = ""
		survey_template_name = inputArray[survey_template_header_idx]
		puts "Service item name = #{survey_template_name}" if @debug_logging_enabled
		survey_template_id = get_survey_template_id(survey_template_name)
		if survey_template_id.nil?
			puts "Didn't find survey template with name = #{survey_template_name}" if @debug_logging_enabled
			itemsNotFound+=1
		else
			@field_values['Attribute_Parent_InstanceId'] = survey_template_id
			puts("Working on row: #{rowcount}") if @debug_logging_enabled
			attribute_array.each do |attribute|
				@field_values['Attribute Type Name'] = attribute
				attribute_type_entry = get_attribute_type(@field_values['Attribute Type Name'])
				if attribute_type_entry.nil?
					if rowcount == 1
						puts "Didn't find attribute type with name = #{@field_values['Attribute Type Name']}" if @debug_logging_enabled
						attributesNotFound+=1
					end
				else
					@field_values['Developer Name'] = attribute_type_entry['Attribute_Data_Type']
					@field_values['Attribute_Data_Type'] = attribute_type_entry['Attribute_Data_Type']
					@field_values['Attribute_Type_Instance_ID'] = attribute_type_entry['instanceId']
					value_field = @field_values['Attribute_Data_Type'] + "_Value"
					if (attribute == "Category")
						attribute_header_idx1 = @headers[0].index("Category1")
						attribute_header_idx2 = @headers[0].index("Category2")
						@field_values['Character_Value'] = inputArray[attribute_header_idx1] + " :: " + inputArray[attribute_header_idx2]
					else
						attribute_header_idx = @headers[0].index(attribute)
						@field_values[value_field] = inputArray[attribute_header_idx]
					end
					if @field_values[value_field].length > 255
						@field_values['Value_Viewer'] = @field_values[value_field].str[0,254]
					else
						@field_values['Value_Viewer'] = @field_values[value_field]
					end
					entry = @@remedy_forms['KS_ATT_AttributeInstance'].create_entry!(
					:field_values => @field_values,
					:fields       => []
					)
				end
			end
		end
	end
	status="Success"
	results_message += "#{records.length} Rows Processed. #{itemsNotFound} Service Items Not Found. #{attributesNotFound} Attributes Not Found"
    results = <<-RESULTS
    <results>
      <result name="Status">#{status}</result>
	  <result name="Error Code">#{error_code}</result>
	  <result name="Result Message">#{results_message}</result>
    </results>
    RESULTS
    puts("Results: \n#{results}") if @debug_logging_enabled
    return results
  end
def execute ( ) status = "" error_code = "" results_message = "" @field_values = { } attribute_list = CSV . parse ( @parameters [ 'attribute_list' ] ) attribute_array = attribute_list [ 0 ] @field_values [ 'Record Status' ] = "Active" @field_values [ 'Status' ] = "Active" @field_values [ 'Application' ] = "Kinetic Request" @field_values [ 'ApplicationName' ] = "Kinetic Request" csvfile = get_attachment ( @parameters [ 'customer_survey_instance_id' ] , @parameters [ 'csv_file' ] , @parameters [ 'survey_template_instance_id' ] ) records = Base64 . decode64 ( csvfile . base64_content ) . split ( / \r ? \n / ) if records . length > 0 headerRow = records [ 0 ] @headers = CSV . parse ( headerRow ) survey_template_header_idx = @headers [ 0 ] . index ( "Service Item Name" ) records . shift end puts "header row found: #{headerRow}" if @debug_logging_enabled puts "header 0: #{@headers[0][0]}" if @debug_logging_enabled puts "Service item name in index #{survey_template_header_idx}" if @debug_logging_enabled rowcount = 0 itemsNotFound = 0 attributesNotFound = 0 records . each do | record | recordArray = CSV . parse ( record ) inputArray = recordArray [ 0 ] puts "processing row found: #{inputArray}" if @debug_logging_enabled rowcount += 1 column_num = 0 survey_template_name = "" survey_template_name = inputArray [ survey_template_header_idx ] puts "Service item name = #{survey_template_name}" if @debug_logging_enabled survey_template_id = get_survey_template_id ( survey_template_name ) if survey_template_id . nil? puts "Didn't find survey template with name = #{survey_template_name}" if @debug_logging_enabled itemsNotFound += 1 else @field_values [ 'Attribute_Parent_InstanceId' ] = survey_template_id puts ( "Working on row: #{rowcount}" ) if @debug_logging_enabled attribute_array . each do | attribute | @field_values [ 'Attribute Type Name' ] = attribute attribute_type_entry = get_attribute_type ( @field_values [ 'Attribute Type Name' ] ) if attribute_type_entry . nil? if rowcount == 1 puts "Didn't find attribute type with name = #{@field_values['Attribute Type Name']}" if @debug_logging_enabled attributesNotFound += 1 end else @field_values [ 'Developer Name' ] = attribute_type_entry [ 'Attribute_Data_Type' ] @field_values [ 'Attribute_Data_Type' ] = attribute_type_entry [ 'Attribute_Data_Type' ] @field_values [ 'Attribute_Type_Instance_ID' ] = attribute_type_entry [ 'instanceId' ] value_field = @field_values [ 'Attribute_Data_Type' ] + "_Value" if ( attribute == "Category" ) attribute_header_idx1 = @headers [ 0 ] . index ( "Category1" ) attribute_header_idx2 = @headers [ 0 ] . index ( "Category2" ) @field_values [ 'Character_Value' ] = inputArray [ attribute_header_idx1 ] + " :: " + inputArray [ attribute_header_idx2 ] else attribute_header_idx = @headers [ 0 ] . index ( attribute ) @field_values [ value_field ] = inputArray [ attribute_header_idx ] end if @field_values [ value_field ] . length > 255 @field_values [ 'Value_Viewer' ] = @field_values [ value_field ] . str [ 0 , 254 ] else @field_values [ 'Value_Viewer' ] = @field_values [ value_field ] end entry = @@remedy_forms [ 'KS_ATT_AttributeInstance' ] . create_entry! ( :field_values => @field_values , :fields => [ ] ) end end end end status = "Success" results_message += "#{records.length} Rows Processed. #{itemsNotFound} Service Items Not Found. #{attributesNotFound} Attributes Not Found" results = <<-RESULTS 
    <results>
      <result name="Status"> #{ status } </result>
	  <result name="Error Code"> #{ error_code } </result>
	  <result name="Result Message"> #{ results_message } </result>
    </results>
     RESULTS puts ( "Results: \n#{results}" ) if @debug_logging_enabled return results end
Creates a record in the KS_SRV_Helper form
This is a required method that is automatically called by the Kinetic Task
Engine.
Creates a record in the KS_SRV_Helper form This is a required method that is automatically called by the Kinetic Task Engine .
# Initialize Results variables #Set Static field values # Retrieve the CSV file # csvfile is an ARSmodels attachment type.  The base64_content contains the actual file content. #get the header row # Set variables #need to get service request instance ID #if you didn't get this template ID, skip the rest of the processing for this row #create attribute entry #Get Attibute Type Info #if you didn't find this attribute, skip the rest of the processing for this attribute #get substring of value for viewer # Create the KS_SRV_Helper record using the @field_values hash # that was built up.  Pass 'Associations ID' to the fields # argument because these fields will be used in the results xml. # Build the results xml that will be returned by this handler. # Return the results String