Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filtered copying #142

Open
wants to merge 1 commit into
base: feature/copyFilteredRecords
Choose a base branch
from

Conversation

aimaj
Copy link
Contributor

@aimaj aimaj commented Aug 22, 2023

@tprouvot
Copy link
Owner

Hi @aimaj,

Thank you very much for this PR and for helping me on this ! 🙏
Could you change the target branch to copyFilterRecords so that you'll be added as contributor !

@aimaj aimaj changed the base branch from master to feature/copyFilteredRecords August 22, 2023 23:39
@aimaj aimaj marked this pull request as ready for review August 22, 2023 23:41
@tprouvot
Copy link
Owner

Hi @aimaj thanks for the updates !
When i paste json copy in data import there's an issue with the new exported data.

Could you take a look ?
I managed to solve the issue without testing a lot but here's the method:

getDataFromJson(json) {
    json = JSON.parse(json);
    let csv;
    let fields = Object.values(json[0]);
    fields = fields.filter(field => field != "attributes");

    let sobject = json[1][0]["attributes"]["type"];
    if (sobject) {
      csv = json.map((row) => {
        return fields.map((fieldName) => {
          let value = fieldName == "_" ? sobject : row[0][fieldName];
          if (typeof value == "boolean" || (value && typeof value !== "object")) {
            return fieldName == "_" ? '"[' + sobject + ']"' : JSON.stringify(value);
          }
        }).join(",");
      });
      fields = fields.map(str => '"' + str + '"');
      csv.unshift(fields.join(","));
      csv = csv.join("\r\n");
    }
    return csv;
  }

@aimaj-salesforce
Copy link
Contributor

@tprouvot it looks like these changes compared to master will unintentionally modify the json export format? and add the header row as an output element

i dont think its intentional or necessary to change the export format, in order to implement the filtered copying so recommend we change this feature to leave the export format as it was before, and then will not require any patching on the import code

thanks for finding this, if you agree i will make the necessary changes in this branch and try and add a unit test for this case

from:

[
  {
    "attributes": {
      "type": "Account",
      "url": "/services/data/v57.0/sobjects/Account/***"
    },
    "Id": "***",
    "LastName": "ABCDEF"
  }
]

to:


[
  [
    "_",
    "Id",
    "LastName"
  ],
  [{
    "attributes": {
      "type": "Account",
      "url": "/services/data/v57.0/sobjects/Account/***"
    },
    "Id": "***",
    "LastName": "ABCDEF"
  }]
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants