Ilogic to populate legacy files with current Custom iProperties, without clearing all data.

Ilogic to populate legacy files with current Custom iProperties, without clearing all data.

ethan.scott.downey
Explorer Explorer
219 Views
3 Replies
Message 1 of 4

Ilogic to populate legacy files with current Custom iProperties, without clearing all data.

ethan.scott.downey
Explorer
Explorer

Hi there, 

 

My knowledge with coding is very basic. I have written this small code to update old legacy files with my current Custom iProperties. The code is basic but it does the job. The only problem i have, is that it overrides any value that is within the legacy file with a blank field. 

 

How do i get this code to skip a iProperty when the value isnt blank?

 

Here is the code: 

Dim CustomNumber As Double

iProperties.Value("Custom", "Approved By Author") = oPropValue
iProperties.Value("Custom", "Approved By Date") = oType_Date
iProperties.Value("Custom", "Checked By Author") = oPropValue
iProperties.Value("Custom", "Checked By Date") = oType_Date
iProperties.Value("Custom", "Description") = oPropValue
iProperties.Value("Custom", "Description1") = oPropValue
iProperties.Value("Custom", "Description2") = oPropValue
iProperties.Value("Custom", "Display Name") = oPropValue
iProperties.Value("Custom", "Document Status") = oPropValue
iProperties.Value("Custom", "Document Status By") = oPropValue
iProperties.Value("Custom", "Document Status Comment") = oPropValue
iProperties.Value("Custom", "Document Status Date") = oType_Date
iProperties.Value("Custom", "Document Status Watermark") = oPropValue
iProperties.Value("Custom", "Drawing Number") = oPropValue
iProperties.Value("Custom", "Drawn By Author") = oPropValue
iProperties.Value("Custom", "Drawn By Date") = oType_Date
iProperties.Value("Custom", "Custom File Name") = oPropValue

 

Any help is much appreciated. 

 

Regards

Ethan

0 Likes
220 Views
3 Replies
Replies (3)
Message 2 of 4

CattabianiI
Collaborator
Collaborator

As you setting the iProperty just check before if that property has some value:

if String.IsNullOrEmpty(iProperties.Value("Custom", "Approved By Author")) Then
iProperties.Value("Custom", "Approved By Author") = oPropValue
else
    ' Do not override legacy iProperty value
End If 

* snippet edited 

0 Likes
Message 3 of 4

ethan.scott.downey
Explorer
Explorer

Thanks for your reply. 

I tried this code, but it still clears the values. If I replace the "Not String" with "String" then it skips the Iproperty when it has some value. However, If the Iproperty doesnt exist, then it errors out. Should i also be checking if the property exist or not, before checking for a value?

0 Likes
Message 4 of 4

A.Acheson
Mentor
Mentor

Hi @ethan.scott.downey  you are correct in needing to check the value exists.  Use try catch statement to check the error of no iProperty existing. 

 

Here is working code. Remove the message box/comment after you test.

 

Dim oPropValue As String = "Hello"

'Check iProperty exists.
Try
	'Check iproperty exists but value is empty.
	If String.IsNullOrEmpty(iProperties.Value("Custom", "Approved By Author").ToString) Then
    	iProperties.Value("Custom", "Approved By Author") = oPropValue
	Else
    	' Do not override legacy iProperty value
		MessageBox.Show(iProperties.Value("Custom", "Approved By Author").ToString, "Approved By Author-iprop Check-Legacy Value")
	End If 
	
'Doesn't exist, so create iProperty and set value.
Catch
	MessageBox.Show("Creating iproperty", "Approved By Author- iprop Check")

	iProperties.Value("Custom", "Approved By Author") = oPropValue
End Try

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan