I'm trying to add some items to another mod's merchant, without necessarily requiring the other mod to be installed. The NPC is already a functional general goods merchant, complete with services faction and container, I just need to add one more leveled item list to his stock that will respawn whenever he restocks.
So, I created a new chest in my own mod (in the WEMerchantChests cell, next to the road peddler chest) which contains only the leveled list I need to add. Then I created a new services faction (cloned from Belethor's) which points to my new chest reference.
Then at run-time, when the player enters the cell with the other mod's merchant, I use GetFormFromFile to retrieve the actor reference (can't do it sooner because he's not persistent, so it won't load until the player is in the cell), and then SetFactionRank to put him in my added services faction at rank 0. This happens before I open dialogue with him, and I checked in the log that the script has gotten valid pointers for both the actor and the faction.
But of course it doesn't work, or I wouldn't be here. Am I missing something obvious? Is there some other way to add to another mod's respawning merchant stock without having to actually override anything from that mod in my own .esp file?