0

As I'm just getting started with SSJS scripting I need help for the below scenario. I have a DE which consist of Contact_ID & Mobile_Number fields. I need to update _MobileAddress table for mobile number change. I have Script which update _MobileAddress table, but I looking to run it in loop so that it will pull all records for DE and updates the _MobileAddress. Please help me with the below script to run loop. Thank you.

<script runat="server">
    Platform.Load('Core','1');
    var contactId = 111111111;
    var mobileAddressDataView = DataExtension.Init('_MobileAddress');
    var result = mobileAddressDataView.Rows.Update({_MobileNumber: '13333333333'}, ['_ContactID'], [contactId]);
</script>
3
  • The data views are read-only. You can't update them. Commented Jul 26, 2022 at 10:07
  • 1
    @AdamSpriggs, _MobileAddress is not a standard data view - it really is editable. For example: mateuszdabrowski.pl/docs/ssjs/… Commented Jul 26, 2022 at 10:15
  • Ah yeah... not sure I'd build a solution that included something like this. However, MobileConnect is activity data and reporting is such a dumpster fire, that's all we have. Commented Jul 26, 2022 at 12:56

1 Answer 1

1

Try the following script:

var mobileAddressDataView = DataExtension.Init("_MobileAddress");
var rows = mobileAddressDataView.Rows.Lookup(["_ContactID"], [contactId]); // If you want to retrieve only records matching your contactId
var rows = mobileAddressDataView.Rows.Retrieve(); // If you want to retrieve all records in the DE

if(rows.length >= 1) {
      for (i = 0; i < rows.length; i++) {
          var result = mobileAddressDataView.Rows.Update({_MobileNumber:'13333333333'}, ['_ContactID'], [contactId]);
    }
}

You must log in to answer this question.

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