Forum Discussion

GZRService_Acco's avatar
GZRService_Acco
Qrew Trainee
3 months ago
Solved

Pulling Number out of a string

I am trying to pull out a record ID # from an email subject or email body.

I want:

Input -     Re: 4793 - New Ticket -...

Output - 4793

Or

Input - 

Should be handled by: Maintenance

Recipients: Maintenance

Ticket #: 4793

Asset ID: empty

 

Output - 4793

 

How can I accomplish this with jinja in a pipeline?

  • I ended up using a splice to take the first 8 characters minus the first 4.  It won't work on old tickets, but tickets moving forward will work.

    Thanks.

10 Replies

  • This can probably be done just with a QuickBase formula. Can you tell me if the format is always the same? For example, if we look for the phrase "Re:" in the subject line, can we be sure that will be there and the following characters will be the number you are looking for?  

     

    Then the same for the body content. Can I look for the phrase? Ticket #: and pull out the number following?

    • GZRService_Acco's avatar
      GZRService_Acco
      Qrew Trainee

      Yes, the formatting will always be the same.

      Unfortunately, I can't do with a Quickbase Formula.  I'm trying to tie these responses to existing QB records, not create new ones.

  • As Mark suggested, with some simple process guidelines to ensure that Ticket number is always present in the subject line or body of the email you can parse it using a formula field. Standardizing the way that the ticket number is referenced will make your task much easier.

    Rather than trying to parse it inside of the pipeline, pass the entire subject or body to a text field in your record then parse it from there.

  • You can use regex on either the body or the subject.

    The regex for matching everything that is not # or 0-9 is [^#0-9].

  • My Jinja is not strong enough to give you the pipelines formula. But often ChatGPT is amazingly good with a Regex formula that could be used in a Pipeline.

    But if you have the concept of a Ticket and you are trying to attach child records to that Ticket based on the Ticket number mentioned in the subject or body then you could simply write out the email into the child. Table and I can provide you with a formula on the child table to calculate the [Related Ticket].  

  • Something like RegexReplace([emailbody], "[^0-9]", "")  should work assuming there are no other numbers or # characters present. I am not sure about the exact syntax you will need to use for the reference text.

  • I ended up using a splice to take the first 8 characters minus the first 4.  It won't work on old tickets, but tickets moving forward will work.

    Thanks.

  • GZR .. so you are saying that the data only exists in the pipeline at this point and is not yet in a record?

    • GZRService_Acco's avatar
      GZRService_Acco
      Qrew Trainee

      I am trying to update a record's note with the email response.  So I was trying to grab the record ID from the email, search the records in my table for that record ID and then update the notes with the previous value & the email response