Hi. Is it possible to add a JavaScript function to the xml source code?

With Thanks

Rob

Hi. Is it possible to add a JavaScript function to the xml source code?

With Thanks

Rob

I’,m trying to validate RSA ID Nos. The code includes things like the

length (13) and a valid date in the first 6 numbers. But there’s also a

formula to calculate the validity of the last no. The code in VBA is:

Public Function IDValid(ByVal varIdNo As Variant) As Boolean

On Error GoTo ErrHandler

Dim idNo As String

Dim a As Integer, b As Long, c As Integer, d As Integer, i As Integer

```
If IsNull(varIdNo) Then
IDValid = False
Exit Function
Else
idNo = CStr(varIdNo)
End If
idNo = RemoveSpaces(idNo)
If Len(idNo) = 13 Then
a = 0
b = 0
c = 0
d = 0
i = 0
For i = 0 To 5
a = a + CInt(Mid(idNo, i * 2 + 1, 1))
Next
For i = 0 To 5
b = b * 10 + CInt(Mid(idNo, i * 2 + 2, 1))
Next
b = b * 2
Do
c = c + b Mod 10
b = Int(b / 10)
Loop Until b <= 0
c = c + a
d = 10 - (c Mod 10)
If (d = 10) Then d = 0
If (d = CInt(Mid(idNo, 13, 1))) And (IsDate("19" & Mid(idNo, 1, 2)
```

& “/” & Mid(idNo, 3, 2) & “/” & Mid(idNo, 5, 2)) Or IsDate(“20” & Mid(idNo,

1, 2) & “/” & Mid(idNo, 3, 2) & “/” & Mid(idNo, 5, 2))) Then

IDValid = True

Else

IDValid = False

End If

Else

IDValid = False

End If

ExitProc:

On Error Resume Next

Exit Function

ErrHandler:

'Fail quietly

Resume ExitProc

Resume

End Function

Hello,

Unfortunately no. You only have access to the built in logic

https://confluence.dimagi.com/display/commcarepublic/Common+Logic+and+Calculations

and functions

https://confluence.dimagi.com/display/commcarepublic/CommCare+Functions.

If you have a specific use case for a javascript function you might be able

to articulate it here and someone could help you figure out a workaround.

thanks,

Cory

Hi. Is it possible to add a JavaScript function to the xml source code?

With Thanks

Rob–

You received this message because you are subscribed to the Google Groups

"commcare-users" group.

To unsubscribe from this group and stop receiving emails from it, send an

email to commcare-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Hey,

I see. I think you can get pretty close to this with a regex but probably

not the whole way there.

Cory

I’,m trying to validate RSA ID Nos. The code includes things like the

length (13) and a valid date in the first 6 numbers. But there’s also a

formula to calculate the validity of the last no. The code in VBA is:Public Function IDValid(ByVal varIdNo As Variant) As Boolean

On Error GoTo ErrHandler

Dim idNo As String

Dim a As Integer, b As Long, c As Integer, d As Integer, i As Integer`If IsNull(varIdNo) Then IDValid = False Exit Function Else idNo = CStr(varIdNo) End If idNo = RemoveSpaces(idNo) If Len(idNo) = 13 Then a = 0 b = 0 c = 0 d = 0 i = 0 For i = 0 To 5 a = a + CInt(Mid(idNo, i * 2 + 1, 1)) Next For i = 0 To 5 b = b * 10 + CInt(Mid(idNo, i * 2 + 2, 1)) Next b = b * 2 Do c = c + b Mod 10 b = Int(b / 10) Loop Until b <= 0 c = c + a d = 10 - (c Mod 10) If (d = 10) Then d = 0 If (d = CInt(Mid(idNo, 13, 1))) And (IsDate("19" & Mid(idNo, 1, 2)`

& “/” & Mid(idNo, 3, 2) & “/” & Mid(idNo, 5, 2)) Or IsDate(“20” & Mid(idNo,

1, 2) & “/” & Mid(idNo, 3, 2) & “/” & Mid(idNo, 5, 2))) Then

IDValid = True

Else

IDValid = False

End If

Else

IDValid = False

End If

ExitProc:

On Error Resume Next

Exit Function

ErrHandler:

'Fail quietly

Resume ExitProc

Resume

End Function–

You received this message because you are subscribed to the Google Groups

"commcare-users" group.

To unsubscribe from this group and stop receiving emails from it, send an

email to commcare-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.