Can anyone tell me if this is the correct way to do it.

Certified Associate Developer

  = getdistinctusers(topeople(cons!IP_GRP_ALERTS)),
a!queryRecordType(
  recordType: 'recordType!{3a27d5e6-31ce-4fe1-995f-821c7e573c8a}IP Add Details.fields.{7340349a-5cf6-4b92-a093-9d1d261d7be2}candidateMail',
  fields: 'recordType!{3a27d5e6-31ce-4fe1-995f-821c7e573c8a}IP Add Details.fields.{7340349a-5cf6-4b92-a093-9d1d261d7be2}candidateMail',
  filters: a!queryFilter(
    field: 'recordType!{3a27d5e6-31ce-4fe1-995f-821c7e573c8a}IP Add Details.fields.{7340349a-5cf6-4b92-a093-9d1d261d7be2}candidateMail',
    operator: "=",
    value: true
  ),
  pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 500)
).data

I am using the send email smart service and i used the "topeople" function to send the email to the group members first and then again i used the "user()" function to return a specific info from a field. Is this the correct way ?

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    I see few issues with this expression. There are two outputs here 

    1. from expression getdistinctusers(topeople(cons!IP_GRP_ALERTS)),

    2. from the query record type

    An expression should have one output so you need to concat the results.

    Another issue is your field "candidateMail".  You are filtering to find records where this field has value as true(). The output of this queryrecord() will be true or null only depending on data. It won't return any username or email address. 

    So check the query record expression in a separate expression and tweak it until it returns the data you need here. Secondly put a concat outside the two expressions (getdistinctusers() as well as query record output).

    Also, if you are passing the constant containing group in it you don't need a topeople() function. getdistinctuser will give the expected output. 

Reply
  • 0
    Certified Lead Developer

    I see few issues with this expression. There are two outputs here 

    1. from expression getdistinctusers(topeople(cons!IP_GRP_ALERTS)),

    2. from the query record type

    An expression should have one output so you need to concat the results.

    Another issue is your field "candidateMail".  You are filtering to find records where this field has value as true(). The output of this queryrecord() will be true or null only depending on data. It won't return any username or email address. 

    So check the query record expression in a separate expression and tweak it until it returns the data you need here. Secondly put a concat outside the two expressions (getdistinctusers() as well as query record output).

    Also, if you are passing the constant containing group in it you don't need a topeople() function. getdistinctuser will give the expected output. 

Children
  • 0
    Certified Associate Developer
    in reply to Harsha Sharma

    So i am using this code to retrieve the candidate mail from the candidatemail field so that, the email is sent to the mail address mentioned in the candidatemail field. But i think maybe i might've been wrong so do i need to do something else or add any more code because i am not getting any mail for right now.

  • 0
    Certified Lead Developer
    in reply to skzahed_09

    Yes there are some issues here! Try to change the code like below and verify what sort of data is in candidateId as well as candidateMail field. 

    recordtype: should be just the record without any field reference. So update it till 'IP App Details' only. 

    filters: you are telling the system to query records where candidate is true(). Now by the name I think this field should have the Ids and not boolean values like true() and false(). So instead of true() pass a candidateId here - put any test value from the record here just to verify. later using rule inputs you can pass the candidate ifd from the process into this one. If you have a pv!recruiterId and another pv!candidate id then you can customise the code like below. If you have this expression within process model then use pv variables only else make sure to pass those pv data as rule input in the expression rule configured.

    a!queryRecordType(
    recordType:recordtype!IP Add Details,
    filters:a!queryfilter(
    field:recordtype!recordName.candidateId,
    operator:"in",
    value:{ri!recruiterId,ri!candidateId}
    ),
    pagingInfo:a!pagingInfo(1,5000)
    ).data

    I would suggest to test this expression first in an expression rule until you get desired mail ids as output. Then only related or use it in process model.

  • 0
    Certified Associate Developer
    in reply to Harsha Sharma

    So iam a little confused about where am i supposed to create these rule inputs. Should it be in the interface of the select candidate or from where iam retrieving the candidate details ?

  • 0
    Certified Lead Developer
    in reply to skzahed_09

    If I understood correctly you have an interface where recruiter selects a candidate. Then you pass the data from interface to process model. 

    In the process model you want to send email to a group as well as the recruiter and selected candidate. Is my understanding correct so far? 

  • 0
    Certified Associate Developer
    in reply to Harsha Sharma

    Actually i have an interface where panel members select the candidate.

    After the panel members click on yes, the status of the candidate will be updated to approved (Just a brief not relevant to the above doubt)

    And at the same time, a mail is supposed to be sent to the recruiter who hired the candidate and also the candidate.

  • 0
    Certified Lead Developer
    in reply to skzahed_09

    Got it! 

    So on click of Yes hope you are doing submit :true() so that process starts. 

    In the process model you can add a script task where you can add code like below and store the output in pv!emailRecipients

    append(getdistinctusers(cons!IP_GRP_ALERTS),
    toemailaddress(pp!initiator), /*This will give the Recruiter's email id*/
    toemiladdress(a!queryRecordType(
      recordType: IP Add Details,
      fields: IP Add Details.candidateMail,
      filters: a!queryFilter(
        field: IP Add Details.candidateId,
        operator: "=",
        value: pv!selectedCandidateId /* Replace this with record field or pv which has the selected candidate Id*/
      ),
      pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 500)
    ).data))

    map the pv!emailRecipients in the To field of the Send e-mail node. Try this and let me know if any doubts or errors are there

  • 0
    Certified Associate Developer
    in reply to Harsha Sharma

    Maybe i confused you a little, because in here the panel is the one who will select the candidates and when the panel member selects a candidate, the candidate will be scheduled for an interview which will be notified to the recruiter who is hiring the candidate and also the candidate to prepare for an interview.

    So there is no need to send the mail to the alerts group, we need to retrieve the data from this record table below 

    we need to retrieve the data from the fields candidatemail and recruiterID. so that the mails will be sent to the recruiter who is in charge of the candidate and the candidate.

  • 0
    Certified Lead Developer
    in reply to skzahed_09

    okay...in that case you can adjust wherever you have the send email node before that add the script task and use append(..) to combine all the email addresses of recipients together. You can refer the above code and adjust the fields as per the data you have in process. configuration of using the output of script task in the send email node will be same as described prevously.

  • 0
    Certified Associate Developer
    in reply to Harsha Sharma

    can you please go through the above reply once again as i have just editd it right now and explained it better in the above one.

  • 0
    Certified Lead Developer
    in reply to skzahed_09

    I the table just have recruiter id in it. You will need to get the user's email id  by querying a table I believe.

    If the above record is being passed to the process model then your script task expression can be something like below

    append(
    toemailaddress(pv!record.candidateMail), /*This will give the Recruiter's email id*/
    toemiladdress(a!queryRecordType(
      recordType:Record that stores recruiter's email,
      fields: above record field reference for recruiters email,
      filters: a!queryFilter(
        field:above record field reference for recruiters Id,
        operator: "=",
        value: pv!record.recruiterId /* Replace this with record field or pv which has the selected candidate Id*/
      ),
      pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 500)
    ).data))