Back to forum list… Back to How Do I?...

Subscript out of range (5 replies)

Arline Welty
9 years ago
Arline Welty 9 years ago

Greetings all,

I am encountering occasional IMAN errors during a CSV import to the Person entity in CRM. It does not happen on every record. I suspect it may be bad data in the CSV, but even if that is true, I am looking for advice on how to handle this. The issue seems to be with my Person First Name function- I have to split it into 2 fields from 1 field.

During the first map transform, I can successfully get the CompanyId value. But sometimes the job fails and I see this error:

Error whilst evaluating field [FIRSTNAME] on transaction type [Record].

Resolved Function - Split("", " ")(0) '

Error - Description: Subscript out of range: '[number: 0]'

Line=1 Pos=0

Here are the functions I am using:

Firstname:

Split(%APCONTACTNAME, " ")(0) '

LastName:

Split(%APCONTACTNAME, " ")(Ubound(Split(%APCONTACTNAME, " "))) '

Why might this work with some person records but not others? 

Thanks in advance for your feedback.

Support
9 years ago
Support 9 years ago

Arline, the reason you are getting an error is the Split function can return an array with no elements.

This will be the case where there is an empty value to split i.e. "".

So, you need to test the array for the number of elements prior to accessing it.

Dim Values 'This is the array variable.
Dim Result 'This is your result variable.
Values = Split("", " ")
If UBound(Values) > 0 Then
  Result = Values(0)
End If
'The last line of the formula becomes the result.
Result
Dim Values 'This is the array variable.
Dim Result 'This is your result variable.
Values = Split("", " ")
If UBound(Values) > 0 Then
  Result = Values(0)
End If
'The last line of the formula becomes the result.
Result
Arline Welty
9 years ago
Arline Welty 9 years ago

Thanks so much for this tip. It's working great for the first part of my name array. It is complaining on the second part even after different permutations. Any suggestions?

First Name field works perfectly like so:

--------------------------------------------------

Dim Values 'This is the array variable.

Dim Result 'This is your result variable.

Values = Split(%APCONTACTNAME, " ")

If UBound(Values) > 0 Then

Result = Values(0)

End If

'The last line of the formula becomes the result.

Result

But the Last Name piece isn't as happy. I've used both the below scripts and see an error (posted below):

----------------------------------------------

Dim Values 'This is the array variable.

Dim Result 'This is your result variable.

Values = Split(%APCONTACTNAME, " ")(Ubound(Split(%APCONTACTNAME, " "))) '

If UBound(Values) > 0 Then

Result = Values(0)

End If

'The last line of the formula becomes the result.

Result

Also tried:

Dim Values 'This is the array variable.

Dim Result 'This is your result variable.

Values = Split(%APCONTACTNAME, " ")(Ubound(Split(%APCONTACTNAME, " "))) '

If (Values) > 0 Then

Result = Values(0)

End If

'The last line of the formula becomes the result.

Result

The error I'm seeing during the transform (doing the "Script Evaluation" shows "No Errors Found"):

Error given:

Error whilst evaluating field [LASTNAME] on transaction type [Record].

Resolved Function - LASTNAME

Error - Description: Type mismatch: 'Ubound'

Line=6 Pos=0

Support
9 years ago
Support 9 years ago

Arline, if I understand correctly, you're trying to obtain the last 'word' in the string.

VBScript is very strict in what it expects i.e. you need to explicitly test for conditions which may cause an error.

Dim Result
Dim Values
Values = Split(%APCONTACTNAME, " ")
'If Split returns a -1, that means the string (APCONTACTNAME) is empty.
If UBound(Values) = -1 Then
  Result = ""
Else
  'Othewise grab the last segment of the array.
  Result = Values(UBound(Values))
End If
Result
Dim Result
Dim Values
Values = Split(%APCONTACTNAME, " ")
'If Split returns a -1, that means the string (APCONTACTNAME) is empty.
If UBound(Values) = -1 Then
  Result = ""
Else
  'Othewise grab the last segment of the array.
  Result = Values(UBound(Values))
End If
Result
Arline Welty
9 years ago
Arline Welty 9 years ago

Breakthrough! Thanks!

8 years ago
Arline Welty 8 years ago

Closed due to inactivity.

Contact

Realisable Software Ltd provides code-free, cost-effective applications integration solutions for SMEs. Our core IMan product is designed to integrate almost any application with a number of Sage solutions and online payment processors.

Looking to purchase IMan, please see our resellers here.

Realisable Software
Ph: +44 (0) 208 123 1017

Copyright © Realisable. All rights reserved.
Realisable is a registered trademark

Close

Request Demo

Realisable Software Ltd provides code-free, cost-effective applications integration solutions for SMEs. Our core IMan product is designed to integrate almost any application with a number of Sage solutions and online payment processors.

Looking to purchase IMan, please see our resellers here.

Realisable Software
Ph: +44 (0) 208 123 1017

Copyright © Realisable. All rights reserved.
Realisable is a registered trademark

Close

Access Downloads

Realisable Software Ltd provides code-free, cost-effective applications integration solutions for SMEs. Our core IMan product is designed to integrate almost any application with a number of Sage solutions and online payment processors.

Looking to purchase IMan, please see our resellers here.

Realisable Software
Ph: +44 (0) 208 123 1017

Copyright © Realisable. All rights reserved.
Realisable is a registered trademark

Close