-4

I am trying to retrieve data using ssjs from one DE and by using AMP script should populate those values to another DE. I am getting with AMP to ssjs but I am not getting with SSJS to AMP. Can anyone help me on this it would be appreciate. Thanks in advance.

 <script runat="server" language="javascript">
   Platform.Load("Core","1");
   var de1 = DataExtension.Init("EMP001");
   var filter = {Property:"Email",SimpleOperator:"equals",Value:"[email protected]"};
var data=de1.Rows.Retrieve(filter);
     for (var i = 0; i < data.length; i++) {
      var sub = data[i];
var fn=sub.FirstName;
var ln=sub.LastName;
var email=sub.Email;
Variable.SetValue("@fn",fn);
Variable.SetValue("@ln",ln);
Variable.SetValue("@email",email);

    }

</script>
%%=v(@fn)=%%   %%=v(@ln)=%%  %%=v(@email)=%%
 %%[
InsertDE("ssjsksl","Firstname",@fn,"Lastname",@ln,"Email",@email)
]%%

Finally I got the solution

6
  • I don't see any AMPScript here. Jul 18, 2017 at 13:20
  • Have you looked at the SSJS scenarios and code samples in the documentation? Jul 18, 2017 at 13:22
  • Yes Sorry I am not getting basic idea to write Amp script using ssjs values so that Jul 18, 2017 at 13:25
  • 3
    Mate, sometimes going narrow's helpful. People have a straightforward question to answer. I think it'd help if you just backed up a moment and told us what you're trying to do from from a functional perspective. Tell the story and problem.
    – Macca
    Jul 18, 2017 at 14:11
  • Thank you for your kind response mate. actually I have tried with retrieving data using AMP script and used that in ssjs. But I am not getting how to use ssjs retrievable data in AMP script. in a single script we should mix both ssjs and amp . Have to query data using ssjs from one Data extension and should populate that data in another data extension using AMP script Jul 18, 2017 at 14:32

1 Answer 1

8

First I want to start off that passing JSON or other array data back and forth between AMPscript and SSJS is impossible without first breaking it into parts and rebuilding. So if that is what you are looking for, I am sorry to say there is no easy way to do it.

If you just want to pass simple variable data back and forth, you will need to use the SSJS functions GetValue and SetValue.

GetValue is used when you have an AMPScript variable you want to pass into your SSJS.

Ex.

%%[
    SET @Var = "Info"
]%%

<script runat="server" language="javascript">
   set var = Variable.GetValue("@Var");
</script>

Set Value is used when you have a SSJS variable you want to pass into AMPscript.

Ex.

<script runat="server" language="javascript">
   set var = 'Info';
   Variable.SetValue("@Var","var");
</script>

%%=v(@Var)=%%

OUTPUT

Info

If you needed to pass array data between the two languages without breaking it and rebuilding it, you could try posting it into a 'holder' data extension and then have the other language grab it via a retrieve or lookup. But keep in mind this is a lot of resources and may cause huge delays in your process. I would see if you absolutely need to switch between languages or if you can accomplish all in one.

4
  • 2
    Just because you can doesn't mean you should.
    – Macca
    Jul 18, 2017 at 16:23
  • 1
    Agreed 100%, but wanted to provide all options and let them make the choice. I haven't seen a use case yet, but who knows, maybe this is it! Jul 18, 2017 at 16:43
  • Thank you for your response. I need to write mixing of both ssjs and ampscript to retrieve data using ssjs then by using those values should populate in another data extension(create). Jul 19, 2017 at 6:47
  • HI everyone I got solution for my requirement thank you Gortonington your code help me to complete this Jul 19, 2017 at 13:48

Not the answer you're looking for? Browse other questions tagged .