This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Break up email subject and map to properties

If I poll a mailbox using M-Files, and the subject line has 4 delimiters, how can I map the data for each value in the subject line to properties on the class?



I am familiar with regex so no issues wtih this approach, but am not clear how. The only thing I can come up with is to map the entire subject line to a property, and then run a script on that property which uses regex to break up the 5 values in the subject line to map to properties. Again, my only issue is how.

If someone has any suggestions or samples they can share that would be great.

Regards

Adam

Parents
  • Hi Adam,

    Have done something similar. Below is the active part of my script as inspiration. I have it running in an Event Handler that is triggered after mailimport. In this step I just split the filename and place the values in separate text properties. Some of them need to be converted to lookup values. I have deliberately kept that as separate operation to allow for manual error handling in cases where the imported filename might not fully comply with expected format or content. Note that by default the Split function uses space as delimiter. This can be configured differently if you need to. See https://www.w3schools.com/asp/func_split.asp

    	Dim oFileNameSegments
    	dim iPDUplFileName : iPDUplFileName = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("PD.UploadedFileName")
    	Dim szUplFileNameF : szUplFileNameF = PropertyValues.SearchForProperty(iPDUplFileName).TypedValue.DisplayValue
    	Dim szUplFileName : szUplFileName = Replace(szUplFileNameF,"  "," ") 'remove incidental double spaces
    	if len(szUplFileName & "") > 0 then
    		oFileNameSegments = split(szUplFileName)
    	else
    		Dim oFilelist : set oFileList = Vault.ObjectFileOperations.GetFiles(ObjVer)
    		If oFileList.Count > 0 then 
    			Dim szFileName1 : szFileName1 = oFileList.Item(1).Title
    			oFileNameSegments = split(szFileName1)
    		Else
    			oFileNameSegments = split(PropertyValues.SearchForProperty(0).TypedValue.DisplayValue)
    		End if
    	End if
    	'check that number of segments is qreater that or equal to the number required.
    	'note that the first segment is item 0, so the count needs to be 1 higher than the segment number wanted.
    	Dim thisProperty : set thisProperty = CreateObject("MFilesAPI.PropertyValue")
    	if (uBound(oFileNameSegments) + 1) >= 1 then
    		Dim iPDQCtxt : iPDQCtxt = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("PD.QCtxt.Class")
    		thisProperty.PropertyDef = iPDQCtxt
    		thisProperty.TypedValue.SetValue MFDatatypeText, oFileNameSegments(0)
    		Vault.ObjectPropertyOperations.SetProperty ObjVer, thisProperty 
    	end if
    	if (uBound(oFileNameSegments) + 1) >= 2 then
    		Dim iPDItemNo : iPDItemNo = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("PD.QCtxt.ItemNo")
    		thisProperty.PropertyDef = iPDItemNo
    		thisProperty.TypedValue.SetValue MFDatatypeText, oFileNameSegments(1)
    		Vault.ObjectPropertyOperations.SetProperty ObjVer, thisProperty 
    	end if
    	if (uBound(oFileNameSegments) + 1) >= 3 then
    		Dim iPDSerialNo : iPDSerialNo = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("PD.QCtxt.SerialNo")
    		thisProperty.PropertyDef = iPDSerialNo
    		thisProperty.TypedValue.SetValue MFDatatypeText, oFileNameSegments(2)
    		Vault.ObjectPropertyOperations.SetProperty ObjVer, thisProperty 
    	end if
    	if (uBound(oFileNameSegments) + 1) >= 4 then
    		Dim iPDPuNo : iPDPuNo = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("PD.QCtxt.PurchaseNo")
    		thisProperty.PropertyDef = iPDPuNo
    		thisProperty.TypedValue.SetValue MFDatatypeText, oFileNameSegments(3)
    		Vault.ObjectPropertyOperations.SetProperty ObjVer, thisProperty 
    	end if
    	if (uBound(oFileNameSegments) + 1) >= 5 then
    		Dim iPDTAG : iPDTAG = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("PD.QCtxt.TAG")
    		thisProperty.PropertyDef = iPDTAG
    		thisProperty.TypedValue.SetValue MFDatatypeText, oFileNameSegments(4)
    		Vault.ObjectPropertyOperations.SetProperty ObjVer, thisProperty 
    	end if
    	if (uBound(oFileNameSegments) + 1) >= 6 then
    		Dim iPDVenRef : iPDVenRef = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("PD.QCtxt.VendorRef")
    		thisProperty.PropertyDef = iPDVenRef
    		thisProperty.TypedValue.SetValue MFDatatypeText, oFileNameSegments(5)
    		Vault.ObjectPropertyOperations.SetProperty ObjVer, thisProperty 
    	end if

  • Thank for your the response Karl. Greatly appreciated. I will give it a go and let you know how I go. 

Reply Children
No Data