How can I map lead qualification assessment data to custom fields for my lead using Groovy?

Lead assessment templates enable consistent and predictable assessment for all leads in your sales organization. You can create a Groovy script to include a Before Insert and a Before Update trigger on the Assessment object to map qualification assessment data such as question responses, response ratings, or score and so on to custom fields in your Leads detail page.

The lead qualification templates use the Assessment object and include assessment questions that represent industry best practices, sales methodologies, or a combination of both. Here's a sample of Groovy code that you can include in the assessment object to map the lead assessment data to your custom leads
Note:
You'll need to replace the Custom_Lead_field_c and AssessmentQuestionField_c attribute values with values of your specific custom fields.
********** Update Assessment and Lead Data **********

if(RelatedObjTypeCode == 'LEAD'){

def vo = newView('Lead')

def vc = vo.createViewCriteria()

def vcr = vc.createRow()

def vcitem = vcr.ensureCriteriaItem('LeadId')

vcitem.setOperator('=')

vcitem.setValue(AssessedObjectId)

vc.insertRow(vcr)

vo.appendViewCriteria(vc)

vo.executeQuery()

if(vo.hasNext()){

  def curRow = vo.next();

  curRow.setAttribute('Custom_Lead_field_c',AssessmentQuestionField_c);

}

}